home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 2: Applications / Linux Cubed Series 2 - Applications.iso / editors / emacs / xemacs / xemacs-1.006 / xemacs-1 / lib / xemacs-19.13 / lisp / rmail / rmail.el < prev    next >
Encoding:
Text File  |  1995-07-31  |  79.1 KB  |  2,200 lines

  1. ;;; rmail.el --- main code of "RMAIL" mail reader for Emacs.
  2.  
  3. ;; Copyright (C) 1985, 1986, 1987, 1988, 1993, 1994
  4. ;;; Free Software Foundation, Inc.
  5.  
  6. ;; Maintainer: FSF
  7. ;; Keywords: mail
  8.  
  9. ;; This file is part of XEmacs.
  10.  
  11. ;; XEmacs is free software; you can redistribute it and/or modify it
  12. ;; under the terms of the GNU General Public License as published by
  13. ;; the Free Software Foundation; either version 2, or (at your option)
  14. ;; any later version.
  15.  
  16. ;; XEmacs is distributed in the hope that it will be useful, but
  17. ;; WITHOUT ANY WARRANTY; without even the implied warranty of
  18. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  19. ;; General Public License for more details.
  20.  
  21. ;; You should have received a copy of the GNU General Public License
  22. ;; along with XEmacs; see the file COPYING.  If not, write to the Free
  23. ;; Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  24.  
  25. ;;; Code:
  26.  
  27. ;; Souped up by shane@mit-ajax based on ideas of rlk@athena.mit.edu
  28. ;;   New features include attribute and keyword support, message
  29. ;;   selection by dispatch table, summary by attributes and keywords,
  30. ;;   expunging by dispatch table, sticky options for file commands.
  31.  
  32. ;; Extended by Bob Weiner of Motorola
  33. ;;   New features include: rmail and rmail-summary buffers remain
  34. ;;   synchronized and key bindings basically operate the same way in both
  35. ;;   buffers, summary by topic or by regular expression, rmail-reply-prefix
  36. ;;   variable, and a bury rmail buffer (wipe) command.
  37. ;;
  38.  
  39. (require 'mail-utils)
  40.  
  41. ;; For Emacs V18 compatibility
  42. (and (not (fboundp 'user-original-login-name))
  43.      (fboundp 'user-real-login-name)
  44.      (defalias 'user-original-login-name 'user-real-login-name))
  45. (and (not (fboundp 'buffer-disable-undo))
  46.      (fboundp 'buffer-flush-undo)
  47.      (defalias 'buffer-disable-undo 'buffer-flush-undo))
  48.  
  49. ; These variables now declared in paths.el.
  50. ;(defvar rmail-spool-directory "/usr/spool/mail/"
  51. ;  "This is the name of the directory used by the system mailer for\n\
  52. ;delivering new mail.  It's name should end with a slash.")
  53. ;(defvar rmail-file-name
  54. ;  (expand-file-name "~/RMAIL")
  55. ;  "")
  56.  
  57. ;;;###autoload
  58. (defvar rmail-dont-reply-to-names nil "\
  59. *A regexp specifying names to prune of reply to messages.
  60. A value of nil means exclude your own name only.")
  61.  
  62. ;;;###autoload
  63. (defvar rmail-default-dont-reply-to-names "info-" "\
  64. A regular expression specifying part of the value of the default value of
  65. the variable `rmail-dont-reply-to-names', for when the user does not set
  66. `rmail-dont-reply-to-names' explicitly.  (The other part of the default
  67. value is the user's name.)
  68. It is useful to set this variable in the site customization file.")
  69.  
  70. ;;; XEmacs change: moved rmail-ignored-headers to sendmail.el for the
  71. ;;; benefit of automatically generated autoloads.
  72. ;;;minimalist FSF version
  73. ;(defvar rmail-ignored-headers "^via:\\|^mail-from:\\|^origin:\\|^status:\\|^received:\\|^message-id:\\|^summary-line:" "\
  74. ;*Gubbish headers one would rather not see.")
  75.  
  76. ;;;###autoload
  77. (defvar rmail-delete-after-output nil "\
  78. *Non-nil means automatically delete a message that is copied to a file.")
  79.  
  80. ;;;###autoload
  81. (defvar rmail-primary-inbox-list nil "\
  82. *List of files which are inboxes for user's primary mail file `~/RMAIL'.
  83. `nil' means the default, which is (\"/usr/spool/mail/$USER\")
  84. \(the name varies depending on the operating system,
  85. and the value of the environment variable MAIL overrides it).")
  86.  
  87. ;;;###autoload
  88. (defvar rmail-mail-new-frame nil
  89.   "*Non-nil means Rmail makes a new frame for composing outgoing mail.")
  90.  
  91. ;;;###autoload
  92. (defvar rmail-retry-setup-hook nil
  93.   "Hook that `rmail-retry-failure' uses in place of `mail-setup-hook'.")
  94.  
  95. ;; These may be altered by site-init.el to match the format of mmdf files
  96. ;;  delimiting used on a given host (delim1 and delim2 from the config
  97. ;;  files).
  98.  
  99. (defvar mmdf-delim1 "^\001\001\001\001\n"
  100.   "Regexp marking the start of an mmdf message")
  101. (defvar mmdf-delim2 "^\001\001\001\001\n"
  102.   "Regexp marking the end of an mmdf message")
  103.  
  104. (defvar rmail-message-filter nil
  105.   "If non nil, is a filter function for new headers in RMAIL.
  106. Called with region narrowed to unformatted header.")
  107.  
  108. (defvar rmail-reply-prefix "Re: "
  109.   "String to prepend to Subject line when replying to a message.")
  110.  
  111. (defvar rmail-mode-map nil)
  112.  
  113. (defvar rmail-inbox-list nil)
  114. (defvar rmail-keywords nil)
  115.  
  116. ;; Message counters and markers.  Deleted flags.
  117.  
  118. (defvar rmail-current-message nil)
  119. (defvar rmail-total-messages nil)
  120. (defvar rmail-message-vector nil)
  121. (defvar rmail-deleted-vector nil)
  122.  
  123. ;; These are used by autoloaded rmail-summary.
  124.  
  125. (defvar rmail-summary-buffer nil)
  126. (defvar rmail-summary-vector nil)
  127.  
  128. ;; `Sticky' default variables.
  129.  
  130. ;; Last individual label specified to a or k.
  131. (defvar rmail-last-label nil)
  132. ;; Last set of values specified to C-M-n, C-M-p, C-M-s or C-M-l.
  133. (defvar rmail-last-multi-labels nil)
  134. (defvar rmail-last-file nil)
  135. (defvar rmail-last-regexp nil)
  136. (defvar rmail-last-rmail-file (expand-file-name "~/XMAIL"))
  137.  
  138. ;;; Regexp matching the delimiter of messages in UNIX mail format
  139. ;;; (UNIX From lines), minus the initial ^.  Note that if you change
  140. ;;; this expression, you must change the code in rmail-nuke-pinhead-header
  141. ;;; that knows the exact ordering of the \\( \\) subexpressions.
  142. (defvar rmail-unix-mail-delimiter
  143.   (let ((time-zone-regexp
  144.      (concat "\\([A-Z]?[A-Z][A-Z][A-Z]\\( DST\\)?"
  145.          "\\|[-+]?[0-9][0-9][0-9][0-9]"
  146.          "\\|"
  147.          "\\) *")))
  148.     (concat
  149.      "From "
  150.  
  151.      ;; Username, perhaps with a quoted section that can contain spaces.
  152.      "\\("
  153.      "[^ \n]*"
  154.      "\\(\\|\".*\"[^ \n]*\\)"
  155.      "\\)  ?"
  156.  
  157.      ;; The time the message was sent.
  158.      "\\([^ \n]*\\) *"            ; day of the week
  159.      "\\([^ ]*\\) *"            ; month
  160.      "\\([0-9]*\\) *"            ; day of month
  161.      "\\([0-9:]*\\) *"            ; time of day
  162.  
  163.      ;; Perhaps a time zone, specified by an abbreviation, or by a
  164.      ;; numeric offset.
  165.      time-zone-regexp
  166.  
  167.      ;; The year.
  168.      " [0-9][0-9]\\([0-9]*\\) *"
  169.  
  170.      ;; On some systems the time zone can appear after the year, too.
  171.      time-zone-regexp
  172.  
  173.      ;; I'm not sure what this is.
  174.      "\\(remote from [^\n]*\\)?"
  175.  
  176.      "\n"))
  177.   )
  178.  
  179. ;; Perform BODY in the summary buffer
  180. ;; in such a way that its cursor is properly updated in its own window.
  181. (defmacro rmail-select-summary (&rest body)
  182.   (` (progn (if (rmail-summary-displayed)
  183.         (let ((window (selected-window)))
  184.           (save-excursion
  185.             (unwind-protect
  186.             (progn
  187.               (pop-to-buffer rmail-summary-buffer)
  188.               (,@ body))
  189.               (select-window window))))
  190.           (save-excursion
  191.         (set-buffer rmail-summary-buffer)
  192.         (progn (,@ body))))
  193.         (rmail-maybe-display-summary))))
  194.  
  195. ;;;; *** Rmail Mode ***
  196.  
  197. ;;;###autoload
  198. (defun rmail (&optional file-name-arg)
  199.   "Read and edit incoming mail.
  200. Moves messages into file named by `rmail-file-name' (a babyl format file)
  201.  and edits that file in RMAIL Mode.
  202. Type \\[describe-mode] once editing that file, for a list of RMAIL commands.
  203.  
  204. May be called with filename as argument; then performs rmail editing on
  205. that file, but does not copy any new mail into the file."
  206.   (interactive (if current-prefix-arg
  207.            (list (read-file-name "Run rmail on RMAIL file: "
  208.                      nil nil t))))
  209.   (if (string-match "XEmacs" emacs-version)
  210.       (require 'rmail-lucid))
  211.   (or rmail-last-file
  212.       (setq rmail-last-file (expand-file-name "~/xmail")))
  213.   (let* ((file-name (expand-file-name (or file-name-arg rmail-file-name)))
  214.      (existed (get-file-buffer file-name)))
  215.     ;; Like find-file, but in the case where a buffer existed
  216.     ;; and the file was reverted, recompute the message-data.
  217.     (if (and existed (not (verify-visited-file-modtime existed)))
  218.     (progn
  219.       ;; Don't be confused by apparent local-variables spec
  220.       ;; in the last message in the RMAIL file.
  221.       (let ((enable-local-variables nil))
  222.         (find-file file-name))
  223.       (if (and (verify-visited-file-modtime existed)
  224.            (eq major-mode 'rmail-mode))
  225.           (progn (rmail-forget-messages)
  226.              (rmail-set-message-counters))))
  227.       (let ((enable-local-variables nil))
  228.     (find-file file-name)))
  229.     (if (eq major-mode 'rmail-edit-mode)
  230.     (error "Exit Rmail Edit mode before getting new mail."))
  231.     (if (and existed (> (buffer-size) 0))
  232.     ;; Buffer not new and not empty; ensure in proper mode, but that's all.
  233.     (or (eq major-mode 'rmail-mode)
  234.         (rmail-mode-2))
  235.       (rmail-mode-2)
  236.       ;; Convert all or part to Babyl file if possible.
  237.       (rmail-convert-file)
  238.       (goto-char (point-max))
  239.       (if (null rmail-inbox-list)
  240.       (progn
  241.         (rmail-set-message-counters)
  242.         (rmail-show-message))))
  243.     (let ((existing-unseen (rmail-first-unseen-message)))
  244.       (or file-name-arg
  245.       (rmail-get-new-mail))
  246.       ;; Show the first unseen message, which might be from a previous session
  247.       ;; or might have been just read in by rmail-get-new-mail.  Must
  248.       ;; determine already unseen messages first, as rmail-get-new-mail
  249.       ;; positions on the first new message, thus marking it as seen.
  250.       (rmail-show-message existing-unseen))))
  251.  
  252. ;; Given the value of MAILPATH, return a list of inbox file names.
  253. ;; This is turned off because it is not clear that the user wants
  254. ;; all these inboxes to feed into the primary rmail file.
  255. ; (defun rmail-convert-mailpath (string)
  256. ;   (let (idx list)
  257. ;     (while (setq idx (string-match "[%:]" string))
  258. ;       (let ((this (substring string 0 idx)))
  259. ;     (setq string (substring string (1+ idx)))
  260. ;     (setq list (cons (if (string-match "%" this)
  261. ;                  (substring this 0 (string-match "%" this))
  262. ;                this)
  263. ;              list))))
  264. ;     list))
  265.  
  266. ;; Someone said:
  267. ; I have checked that adding "-*- rmail -*-" to the BABYL OPTIONS line
  268. ; will not cause emacs 18.55 problems.
  269. ;; To which jwz responds: maybe so but it's damned annoying so don't do it.
  270.  
  271. (defun rmail-convert-file ()
  272.   (let (convert)
  273.     (widen)
  274.     (goto-char (point-min))
  275.     ;; If file doesn't start like a Babyl file,
  276.     ;; convert it to one, by adding a header and converting each message.
  277.     (cond ((looking-at "BABYL OPTIONS:"))
  278.       ((looking-at "Version: 5\n")
  279.        ;; Losing babyl file made by old version of Rmail.
  280.        ;; Just fix the babyl file header; don't make a new one,
  281.        ;; so we don't lose the Labels: file attribute, etc.
  282.        (let ((buffer-read-only nil))
  283.          ;; NO NO NO
  284.          ;;(insert "BABYL OPTIONS: -*- rmail -*-\n")
  285.          (insert "BABYL OPTIONS:\n")))
  286.       ((equal (point-min) (point-max))
  287.        ;; Empty RMAIL file.  Just insert the header.
  288.        (rmail-insert-rmail-file-header))
  289.       (t
  290.        ;; Non-empty file in non-RMAIL format.  Add header and convert.
  291.        (setq convert t)
  292.        (rmail-insert-rmail-file-header)))
  293.     ;; If file was not a Babyl file or if there are
  294.     ;; Unix format messages added at the end,
  295.     ;; convert file as necessary.
  296.     (if (or convert
  297.         (save-excursion
  298.           (goto-char (point-max))
  299.           (search-backward "\^_")
  300.           (forward-char 1)
  301.           (looking-at "\n*From ")))
  302.     (let ((buffer-read-only nil))
  303.       (message "Converting to Babyl format...")
  304.       ;; If file needs conversion, convert it all,
  305.       ;; except for the BABYL header.
  306.       ;; (rmail-convert-to-babyl-format would delete the header.)
  307.       (goto-char (point-min))
  308.       (search-forward "\n\^_" nil t)
  309.       (narrow-to-region (point) (point-max))
  310.       (rmail-convert-to-babyl-format)
  311.       (message "Converting to Babyl format...done")))))
  312.  
  313. ;;; I have checked that adding "-*- rmail -*-" to the BABYL OPTIONS line
  314. ;;; will not cause emacs 18.55 problems.
  315. ;;; (Whatever, see above. -jwz)
  316.  
  317. (defun rmail-insert-rmail-file-header ()
  318.   (let ((buffer-read-only nil))
  319.     ;; NO NO NO a thousand times NO
  320. ;;    (insert "BABYL OPTIONS: -*- rmail -*-
  321.     (insert "BABYL OPTIONS:
  322. Version: 5
  323. Labels:
  324. Note:   This is the header of an rmail file.
  325. Note:   If you are seeing it in rmail,
  326. Note:    it means the file has no messages in it.\n\^_")))
  327.  
  328. (if rmail-mode-map
  329.     nil
  330.   (setq rmail-mode-map (make-keymap))
  331.   (suppress-keymap rmail-mode-map)
  332.   (define-key rmail-mode-map "a"      'rmail-add-label)
  333.   (define-key rmail-mode-map "b"      'rmail-bury)
  334.   (define-key rmail-mode-map "c"      'rmail-continue)
  335.   (define-key rmail-mode-map "d"      'rmail-delete-forward)
  336.   (define-key rmail-mode-map "\C-d"   'rmail-delete-backward)
  337.   (define-key rmail-mode-map "e"      'rmail-edit-current-message)
  338.   (define-key rmail-mode-map "f"      'rmail-forward)
  339.   (define-key rmail-mode-map "g"      'rmail-get-new-mail)
  340.   (define-key rmail-mode-map "h"      'rmail-summary)
  341.   (define-key rmail-mode-map "i"      'rmail-input)
  342.   (define-key rmail-mode-map "j"      'rmail-show-message)
  343.   (define-key rmail-mode-map "k"      'rmail-kill-label)
  344.   (define-key rmail-mode-map "l"      'rmail-summary-by-labels)
  345.   (define-key rmail-mode-map "\e\C-h" 'rmail-summary)
  346.   (define-key rmail-mode-map "\e\C-l" 'rmail-summary-by-labels)
  347.   (define-key rmail-mode-map "\e\C-r" 'rmail-summary-by-recipients)
  348.   (define-key rmail-mode-map "\e\C-s" 'rmail-summary-by-regexp)
  349.   (define-key rmail-mode-map "\e\C-t" 'rmail-summary-by-topic)
  350.   (define-key rmail-mode-map "m"      'rmail-mail)
  351.   (define-key rmail-mode-map "\em"    'rmail-retry-failure)
  352.   (define-key rmail-mode-map "n"      'rmail-next-undeleted-message)
  353.   (define-key rmail-mode-map "\en"    'rmail-next-message)
  354.   (define-key rmail-mode-map "\e\C-n" 'rmail-next-labeled-message)
  355.   (define-key rmail-mode-map "o"      'rmail-output-to-rmail-file)
  356.   (define-key rmail-mode-map "\C-o"   'rmail-output)
  357.   (define-key rmail-mode-map "p"      'rmail-previous-undeleted-message)
  358.   (define-key rmail-mode-map "\ep"    'rmail-previous-message)
  359.   (define-key rmail-mode-map "\e\C-p" 'rmail-previous-labeled-message)
  360.   (define-key rmail-mode-map "q"      'rmail-quit)
  361.   (define-key rmail-mode-map "r"      'rmail-reply)
  362. ;; I find I can't live without the default M-r command -- rms.
  363. ;;  (define-key rmail-mode-map "\er"  'rmail-search-backwards)
  364.   (define-key rmail-mode-map "s"      'rmail-expunge-and-save)
  365.   (define-key rmail-mode-map "\es"    'rmail-search)
  366.   (define-key rmail-mode-map "t"      'rmail-toggle-header)
  367.   (define-key rmail-mode-map "u"      'rmail-undelete-previous-message)
  368.   (define-key rmail-mode-map "w"      'rmail-edit-current-message)
  369.   (define-key rmail-mode-map "x"      'rmail-expunge)
  370.   (define-key rmail-mode-map "."      'rmail-beginning-of-message)
  371.   (define-key rmail-mode-map "<"      'rmail-first-message)
  372.   (define-key rmail-mode-map ">"      'rmail-last-message)
  373.   (define-key rmail-mode-map " "      'scroll-up)
  374.   (define-key rmail-mode-map "\177"   'scroll-down)
  375.   (define-key rmail-mode-map "?"      'describe-mode)
  376.   (define-key rmail-mode-map "\C-c\C-s\C-d" 'rmail-sort-by-date)
  377.   (define-key rmail-mode-map "\C-c\C-s\C-s" 'rmail-sort-by-subject)
  378.   (define-key rmail-mode-map "\C-c\C-s\C-a" 'rmail-sort-by-author)
  379.   (define-key rmail-mode-map "\C-c\C-s\C-r" 'rmail-sort-by-recipient)
  380.   (define-key rmail-mode-map "\C-c\C-s\C-c" 'rmail-sort-by-correspondent)
  381.   (define-key rmail-mode-map "\C-c\C-s\C-l" 'rmail-sort-by-lines)
  382.   )
  383.  
  384. ;(define-key rmail-mode-map [menu-bar] (make-sparse-keymap))
  385. ;
  386. ;(define-key rmail-mode-map [menu-bar classify]
  387. ;  (cons "Classify" (make-sparse-keymap "Classify")))
  388. ;
  389. ;(define-key rmail-mode-map [menu-bar classify output-inbox]
  390. ;  '("Output (inbox)" . rmail-output))
  391. ;
  392. ;(define-key rmail-mode-map [menu-bar classify output]
  393. ;  '("Output (Rmail)" . rmail-output-to-rmail-file))
  394. ;
  395. ;(define-key rmail-mode-map [menu-bar classify kill-label]
  396. ;  '("Kill Label" . rmail-kill-label))
  397. ;
  398. ;(define-key rmail-mode-map [menu-bar classify add-label]
  399. ;  '("Add Label" . rmail-add-label))
  400. ;
  401. ;(define-key rmail-mode-map [menu-bar summary]
  402. ;  (cons "Summary" (make-sparse-keymap "Summary")))
  403. ;
  404. ;(define-key rmail-mode-map [menu-bar summary labels]
  405. ;  '("By Labels" . rmail-summary-by-labels))
  406. ;
  407. ;(define-key rmail-mode-map [menu-bar summary recipients]
  408. ;  '("By Recipients" . rmail-summary-by-recipients))
  409. ;
  410. ;(define-key rmail-mode-map [menu-bar summary topic]
  411. ;  '("By Topic" . rmail-summary-by-topic))
  412. ;
  413. ;(define-key rmail-mode-map [menu-bar summary regexp]
  414. ;  '("By Regexp" . rmail-summary-by-regexp))
  415. ;
  416. ;(define-key rmail-mode-map [menu-bar summary all]
  417. ;  '("All" . rmail-summary))
  418. ;
  419. ;(define-key rmail-mode-map [menu-bar mail]
  420. ;  (cons "Mail" (make-sparse-keymap "Mail")))
  421. ;
  422. ;(define-key rmail-mode-map [menu-bar mail continue]
  423. ;  '("Continue" . rmail-continue))
  424. ;
  425. ;(define-key rmail-mode-map [menu-bar mail forward]
  426. ;  '("Forward" . rmail-forward))
  427. ;
  428. ;(define-key rmail-mode-map [menu-bar mail retry]
  429. ;  '("Retry" . rmail-retry-failure))
  430. ;
  431. ;(define-key rmail-mode-map [menu-bar mail reply]
  432. ;  '("Reply" . rmail-reply))
  433. ;
  434. ;(define-key rmail-mode-map [menu-bar mail mail]
  435. ;  '("Mail" . rmail-mail))
  436. ;
  437. ;(define-key rmail-mode-map [menu-bar delete]
  438. ;  (cons "Delete" (make-sparse-keymap "Delete")))
  439. ;
  440. ;(define-key rmail-mode-map [menu-bar delete expunge/save]
  441. ;  '("Expunge/Save" . rmail-expunge-and-save))
  442. ;
  443. ;(define-key rmail-mode-map [menu-bar delete expunge]
  444. ;  '("Expunge" . rmail-expunge))
  445. ;
  446. ;(define-key rmail-mode-map [menu-bar delete undelete]
  447. ;  '("Undelete" . rmail-undelete-previous-message))
  448. ;
  449. ;(define-key rmail-mode-map [menu-bar delete delete]
  450. ;  '("Delete" . rmail-delete-forward))
  451. ;
  452. ;(define-key rmail-mode-map [menu-bar move]
  453. ;  (cons "Move" (make-sparse-keymap "Move")))
  454. ;
  455. ;(define-key rmail-mode-map [menu-bar move search-back]
  456. ;  '("Search Back" . rmail-search-backward))
  457. ;
  458. ;(define-key rmail-mode-map [menu-bar move search]
  459. ;  '("Search" . rmail-search))
  460. ;
  461. ;(define-key rmail-mode-map [menu-bar move previous]
  462. ;  '("Previous Nondeleted" . rmail-previous-undeleted-message))
  463. ;
  464. ;(define-key rmail-mode-map [menu-bar move next]
  465. ;  '("Next Nondeleted" . rmail-next-undeleted-message))
  466. ;
  467. ;(define-key rmail-mode-map [menu-bar move last]
  468. ;  '("Last" . rmail-last-message))
  469. ;
  470. ;(define-key rmail-mode-map [menu-bar move first]
  471. ;  '("First" . rmail-first-message))
  472. ;
  473. ;(define-key rmail-mode-map [menu-bar move previous]
  474. ;  '("Previous" . rmail-previous-message))
  475. ;
  476. ;(define-key rmail-mode-map [menu-bar move next]
  477. ;  '("Next" . rmail-next-message))
  478.  
  479. ;; Rmail mode is suitable only for specially formatted data.
  480. (put 'rmail-mode 'mode-class 'special)
  481.  
  482. ;;;###autoload
  483. (defun rmail-mode ()
  484.   "Rmail Mode is used by \\<rmail-mode-map>\\[rmail] for editing Rmail files.
  485. All normal editing commands are turned off.
  486. Instead, these commands are available:
  487.  
  488. \\[rmail-beginning-of-message]    Move point to front of this message (same as \\[beginning-of-buffer]).
  489. \\[scroll-up]    Scroll to next screen of this message.
  490. \\[scroll-down]    Scroll to previous screen of this message.
  491. \\[rmail-next-undeleted-message]    Move to Next non-deleted message.
  492. \\[rmail-previous-undeleted-message]    Move to Previous non-deleted message.
  493. \\[rmail-next-message]    Move to Next message whether deleted or not.
  494. \\[rmail-previous-message]    Move to Previous message whether deleted or not.
  495. \\[rmail-first-message]    Move to the first message in Rmail file.
  496. \\[rmail-last-message]    Move to the last message in Rmail file.
  497. \\[rmail-show-message]    Jump to message specified by numeric position in file.
  498. \\[rmail-search]    Search for string and show message it is found in.
  499. \\[rmail-delete-forward]    Delete this message, move to next nondeleted.
  500. \\[rmail-delete-backward]    Delete this message, move to previous nondeleted.
  501. \\[rmail-undelete-previous-message]    Undelete message.  Tries current message, then earlier messages
  502.     till a deleted message is found.
  503. \\[rmail-edit-current-message]    Edit the current message.  \\[rmail-cease-edit] to return to Rmail.
  504. \\[rmail-expunge]    Expunge deleted messages.
  505. \\[rmail-expunge-and-save]    Expunge and save the file.
  506. \\[rmail-quit]       Quit Rmail: expunge, save, then switch to another buffer.
  507. \\[save-buffer] Save without expunging.
  508. \\[rmail-get-new-mail]    Move new mail from system spool directory into this file.
  509. \\[rmail-mail]    Mail a message (same as \\[mail-other-window]).
  510. \\[rmail-continue]    Continue composing outgoing message started before.
  511. \\[rmail-reply]    Reply to this message.  Like \\[rmail-mail] but initializes some fields.
  512. \\[rmail-retry-failure]    Send this message again.  Used on a mailer failure message.
  513. \\[rmail-forward]    Forward this message to another user.
  514. \\[rmail-output-to-rmail-file]       Output this message to an Rmail file (append it).
  515. \\[rmail-output]    Output this message to a Unix-format mail file (append it).
  516. \\[rmail-input]    Input Rmail file.  Run Rmail on that file.
  517. \\[rmail-add-label]    Add label to message.  It will be displayed in the mode line.
  518. \\[rmail-kill-label]    Kill label.  Remove a label from current message.
  519. \\[rmail-next-labeled-message]   Move to Next message with specified label
  520.           (label defaults to last one specified).
  521.           Standard labels: filed, unseen, answered, forwarded, deleted.
  522.           Any other label is present only if you add it with \\[rmail-add-label].
  523. \\[rmail-previous-labeled-message]   Move to Previous message with specified label
  524. \\[rmail-summary]    Show headers buffer, with a one line summary of each message.
  525. \\[rmail-summary-by-labels]    Summarize only messages with particular label(s).
  526. \\[rmail-summary-by-recipients]   Summarize only messages with particular recipient(s).
  527. \\[rmail-summary-by-regexp]   Summarize only messages with particular regexp(s).
  528. \\[rmail-summary-by-topic]   Summarize only messages with subject line regexp(s).
  529. \\[rmail-toggle-header]    Toggle display of complete header."
  530.   (interactive)
  531.   (rmail-mode-2)
  532.   (rmail-set-message-counters)
  533.   (rmail-show-message rmail-total-messages))
  534.  
  535. (defun rmail-mode-2 ()
  536.   (kill-all-local-variables)
  537.   (rmail-mode-1)
  538.   (rmail-variables)
  539.   (run-hooks 'rmail-mode-hook))
  540.  
  541. (defun rmail-mode-1 ()
  542.   (setq major-mode 'rmail-mode)
  543.   (setq mode-name "RMAIL")
  544.   (setq buffer-read-only t)
  545.   ;; No need to auto save RMAIL files.
  546.   ;; says who??? (asks jwz)
  547. ;;  (setq buffer-auto-save-file-name nil)
  548.   (if (boundp 'mode-line-modified)
  549.       (setq mode-line-modified "--- ")
  550.     (setq mode-line-format
  551.       (cons "--- " (cdr (default-value 'mode-line-format)))))
  552.   (use-local-map rmail-mode-map)
  553.   (set-syntax-table text-mode-syntax-table)
  554.   (setq local-abbrev-table text-mode-abbrev-table))
  555.  
  556. (defun rmail-variables ()
  557.   (make-local-variable 'revert-buffer-function)
  558.   (setq revert-buffer-function 'rmail-revert)
  559.   (make-local-variable 'rmail-last-label)
  560.   (make-local-variable 'rmail-last-regexp)
  561.   (make-local-variable 'rmail-deleted-vector)
  562.   (make-local-variable 'rmail-summary-buffer)
  563.   (make-local-variable 'rmail-summary-vector)
  564.   (make-local-variable 'rmail-current-message)
  565.   (make-local-variable 'rmail-total-messages)
  566.   (make-local-variable 'require-final-newline)
  567.   (setq require-final-newline nil)
  568.   (make-local-variable 'version-control)
  569.   (setq version-control 'never)
  570.   (make-local-variable 'file-precious-flag)
  571.   (setq file-precious-flag t)
  572.   (make-local-variable 'rmail-message-vector)
  573.   (make-local-variable 'rmail-last-file)
  574.   (make-local-variable 'rmail-inbox-list)
  575.   (setq rmail-inbox-list (rmail-parse-file-inboxes))
  576.   ;; Provide default set of inboxes for primary mail file ~/RMAIL.
  577.   (and (null rmail-inbox-list)
  578.        (or (equal buffer-file-name (expand-file-name rmail-file-name))
  579.        (equal buffer-file-truename
  580.           (abbreviate-file-name (file-truename rmail-file-name))))
  581.        (setq rmail-inbox-list
  582.          (or rmail-primary-inbox-list
  583.          ;; XEmacs change: FSF had removed "~/mbox" from this list, 
  584.          ;; but users expect that to work and don't understand why
  585.          ;; it changed.
  586.          (list "~/mbox"
  587.                (or (getenv "MAIL")
  588.                (concat rmail-spool-directory
  589.                    (user-original-login-name)))))))
  590.   (make-local-variable 'rmail-keywords)
  591.   ;; this gets generated as needed
  592.   (setq rmail-keywords nil))
  593.  
  594. ;; Handle M-x revert-buffer done in an rmail-mode buffer.
  595. (defun rmail-revert (arg noconfirm)
  596.   (let (revert-buffer-function)
  597.     ;; Call our caller again, but this time it does the default thing.
  598.     (if (revert-buffer arg noconfirm)
  599.     ;; If the user said "yes", and we changed something,
  600.     ;; reparse the messages.
  601.     (progn
  602.       (rmail-convert-file)
  603.       (goto-char (point-max))
  604.       (rmail-set-message-counters)
  605.       (rmail-show-message)))))
  606.  
  607. ;; Return a list of files from this buffer's Mail: option.
  608. ;; Does not assume that messages have been parsed.
  609. ;; Just returns nil if buffer does not look like Babyl format.
  610. (defun rmail-parse-file-inboxes ()
  611.   (save-excursion
  612.     (save-restriction
  613.       (widen)
  614.       (goto-char 1)
  615.       (cond ((looking-at "BABYL OPTIONS:")
  616.          (search-forward "\n\^_" nil 'move)
  617.          (narrow-to-region 1 (point))
  618.          (goto-char 1)
  619.          (if (search-forward "\nMail:" nil t)
  620.          (progn
  621.            (narrow-to-region (point) (progn (end-of-line) (point)))
  622.            (goto-char (point-min))
  623.            (mail-parse-comma-list))))))))
  624.  
  625. (defun rmail-expunge-and-save ()
  626.   "Expunge and save RMAIL file."
  627.   (interactive)
  628.   (rmail-expunge)
  629.   (save-buffer))
  630.  
  631. (defun rmail-quit ()
  632.   "Quit out of RMAIL."
  633.   (interactive)
  634.   (rmail-expunge-and-save)
  635.   ;; Don't switch to the summary buffer even if it was recently visible.
  636.   (if (rmail-summary-exists)
  637.       (bury-buffer rmail-summary-buffer))
  638.   (let ((obuf (current-buffer)))
  639.     (switch-to-buffer (other-buffer))
  640.     (bury-buffer obuf)))
  641.  
  642. ;;;###autoload
  643. (defun rmail-input (filename)
  644.   "Run Rmail on file FILENAME."
  645.   (interactive "FRun rmail on RMAIL file: ")
  646.   (rmail filename))
  647.  
  648.  
  649. ;;;; *** Rmail input ***
  650.  
  651. ;; RLK feature not added in this version:
  652. ;; argument specifies inbox file or files in various ways.
  653.  
  654. (defun rmail-get-new-mail (&optional file-name)
  655.   "Move any new mail from this RMAIL file's inbox files.
  656. The inbox files can be specified with the file's Mail: option.  The
  657. variable `rmail-primary-inbox-list' specifies the inboxes for your
  658. primary RMAIL file if it has no Mail: option.  By default, this is
  659. your /usr/spool/mail/$USER.
  660.  
  661. You can also specify the file to get new mail from.  In this case, the
  662. file of new mail is not changed or deleted.  Noninteractively, you can
  663. pass the inbox file name as an argument.  Interactively, a prefix
  664. argument causes us to read a file name and use that file as the inbox."
  665.   (interactive
  666.    (list (if current-prefix-arg
  667.          (read-file-name "Get new mail from file: "))))
  668.   (or (verify-visited-file-modtime (current-buffer))
  669.       (progn
  670.     (find-file (buffer-file-name))
  671.     (setq buffer-read-only t)
  672.     (if (verify-visited-file-modtime (current-buffer))
  673.         (rmail-forget-messages))))
  674.   (rmail-maybe-set-message-counters)
  675.   (widen)
  676.   ;; Get rid of all undo records for this buffer.
  677.   (or (eq buffer-undo-list t)
  678.       (setq buffer-undo-list nil))
  679.   (unwind-protect
  680.       (let ((opoint (point))
  681.         (new-messages 0)
  682.         (delete-files ())
  683.         ;; If buffer has not changed yet, and has not been saved yet,
  684.         ;; don't replace the old backup file now.
  685.         (make-backup-files (and make-backup-files (buffer-modified-p)))
  686.         (buffer-read-only nil)
  687.         ;; Don't make undo records for what we do in getting mail.
  688.         (buffer-undo-list t))
  689.     (goto-char (point-max))
  690.     (skip-chars-backward " \t\n")        ; just in case of brain damage
  691.     (delete-region (point) (point-max)) ; caused by require-final-newline
  692.     (save-excursion
  693.       (save-restriction
  694.         (narrow-to-region (point) (point))
  695.         ;; Read in the contents of the inbox files,
  696.         ;; renaming them as necessary,
  697.         ;; and adding to the list of files to delete eventually.
  698.         (if file-name
  699.         (rmail-insert-inbox-text (list file-name) nil)
  700.           (setq delete-files (rmail-insert-inbox-text rmail-inbox-list t)))
  701.         ;; Scan the new text and convert each message to babyl format.
  702.         (goto-char (point-min))
  703.         (save-excursion
  704.           (setq new-messages (rmail-convert-to-babyl-format)))
  705.         (or (zerop new-messages)
  706.         (progn ;;let (success)
  707.           (widen)
  708.           (search-backward "\n\^_")
  709.           (narrow-to-region (point) (point-max))
  710.           (goto-char (1+ (point-min)))
  711.           (rmail-count-new-messages)
  712.           (save-buffer)))
  713.         ;; Delete the old files, now that babyl file is saved.
  714.         (while delete-files
  715.           (condition-case ()
  716.           ;; First, try deleting.
  717.           (condition-case ()
  718.               (delete-file (car delete-files))
  719.             (file-error
  720.              ;; If we can't delete it, truncate it.
  721.              (write-region (point) (point) (car delete-files))))
  722.         (file-error nil))
  723.           (setq delete-files (cdr delete-files)))))
  724.     (if (= new-messages 0)
  725.         (progn (goto-char opoint)
  726.            (if (or file-name rmail-inbox-list)
  727.                (message "(No new mail has arrived)")))
  728.       (if (rmail-summary-exists)
  729.           (rmail-select-summary
  730.         (rmail-update-summary)))
  731.       (message "%d new message%s read"
  732.            new-messages (if (= 1 new-messages) "" "s"))
  733.       ;; #### BOGUS!  Run a hook here instead and let time.el do it.
  734.       (and (boundp 'display-time-string)
  735.            display-time-string
  736.            (string-match " Mail" display-time-string)
  737.            (setq display-time-string
  738.              (concat
  739.               (substring display-time-string 0 (match-beginning 0))
  740.               (substring display-time-string (match-end 0))))
  741.            (force-mode-line-update 'all))))
  742.     ;; Don't leave the buffer screwed up if we get a disk-full error.
  743.     (rmail-show-message)))
  744.  
  745. (defun rmail-insert-inbox-text (files renamep)
  746.   (let (file tofile delete-files movemail popmail)
  747.     (while files
  748.       (setq file (expand-file-name (substitute-in-file-name (car files)))
  749.         ;;>> un*x specific <<
  750.         ;; The "+" used to be "~", which is an extremely poor choice;
  751.         ;; it might accidentally be deleted when space is low
  752.         ;; (as happened to me!).
  753.         tofile (concat file "+"))
  754.       ;; If getting from mail spool directory,
  755.       ;; use movemail to move rather than just renaming,
  756.       ;; so as to interlock with the mailer.
  757.       (setq movemail (equal (file-name-directory file) rmail-spool-directory)
  758.         popmail (string-match "^po:" (file-name-nondirectory file)))
  759.       (if popmail (setq file (file-name-nondirectory file)
  760.             renamep t))
  761.       (if movemail
  762.       (progn
  763.         (setq tofile (expand-file-name
  764.                ;; Generate name to move to from inbox name,
  765.                ;; in case of multiple inboxes that need moving.
  766.                (concat ".newmail-" (file-name-nondirectory file))
  767.                ;; Use the directory of this rmail file
  768.                ;; because it's a nuisance to use the homedir
  769.                ;; if that is on a full disk and this rmail
  770.                ;; file isn't.
  771.                (file-name-directory
  772.                  (expand-file-name buffer-file-name))))
  773.         ;; On some systems, /usr/spool/mail/foo is a directory
  774.         ;; and the actual inbox is /usr/spool/mail/foo/foo.
  775.         (if (file-directory-p file)
  776.         (setq file (expand-file-name (user-original-login-name)
  777.                          file)))))
  778.       (if popmail
  779.       (message "Getting mail from post office ...")
  780.     (if (or (and (file-exists-p tofile)
  781.              (/= 0 (nth 7 (file-attributes tofile))))
  782.         (and (file-exists-p file)
  783.              (/= 0 (nth 7 (file-attributes file)))))
  784.         (message "Getting mail from %s..." file)))
  785.       ;; Set TOFILE if have not already done so, and
  786.       ;; rename or copy the file FILE to TOFILE if and as appropriate.
  787.       (cond ((not renamep)
  788.          (setq tofile file))
  789.         ((or (file-exists-p tofile) (and (not popmail)
  790.                          (not (file-exists-p file))))
  791.          nil)
  792.         ((and (not movemail) (not popmail))
  793.          ;; Try copying.  If that fails (perhaps no space),
  794.          ;; rename instead.
  795.          (condition-case nil
  796.          (copy-file file tofile nil)
  797.            (error
  798.         (rename-file file tofile nil)))
  799.          ;; Make the real inbox file empty.
  800.          ;; Leaving it deleted could cause lossage
  801.          ;; because mailers often won't create the file.
  802.          (condition-case ()
  803.          (write-region (point) (point) file)
  804.            (file-error nil)))
  805.         (t
  806.          (let ((errors nil))
  807.            (unwind-protect
  808.            (save-excursion
  809.              (setq errors (generate-new-buffer " *rmail loss*"))
  810.              (buffer-disable-undo errors)
  811.              (call-process
  812.                (expand-file-name "movemail" exec-directory)
  813.                nil errors nil file tofile)
  814.              (if (not (buffer-modified-p errors))
  815.              ;; No output => movemail won
  816.              nil
  817.                (set-buffer errors)
  818.                (subst-char-in-region (point-min) (point-max)
  819.                          ?\n ?\  )
  820.                (goto-char (point-max))
  821.                (skip-chars-backward " \t")
  822.                (delete-region (point) (point-max))
  823.                (goto-char (point-min))
  824.                (if (looking-at "movemail: ")
  825.                (delete-region (point-min) (match-end 0)))
  826.                (beep t)
  827.                (message (concat "movemail: "
  828.                     (buffer-substring (point-min)
  829.                               (point-max))))
  830.                (sit-for 3)
  831.                nil))
  832.          (if errors (kill-buffer errors))))))
  833.       ;; At this point, TOFILE contains the name to read:
  834.       ;; Either the alternate name (if we renamed)
  835.       ;; or the actual inbox (if not renaming).
  836.       (if (file-exists-p tofile)
  837.       (let (size)
  838.         (goto-char (point-max))
  839.         (if (not (featurep 'mule))
  840.         (setq size (nth 1 (insert-file-contents tofile)))
  841.           ;; At first, read the file without converting coding-system.
  842.           (setq size (nth 1 (let (file-coding-system-for-read)
  843.                   (insert-file-contents tofile))))
  844.           ;; Then, convert the contents if necessary.
  845.           (if (> size 0)
  846.           (cond
  847.            ((looking-at "^From ")
  848.             ;; New mails.  Since the contents may be a mixture
  849.             ;; of various coding-systems, we must decode one
  850.             ;; mail by one.
  851.             (while (null (eobp))
  852.               (let ((from (point)))
  853.             (re-search-forward "^From " nil 'mv)
  854.             (rmail-decode-coding-system from (point)))))
  855.            ((looking-at "BABYL OPTIONS:\\|\^L")
  856.             ;; Babyl format, i.e. not a new mail.  We had better
  857.             ;; not to convert large region at once.
  858.             (while (null (eobp))
  859.               (let ((max-size (* 1024 1024))
  860.                 (from (point)))
  861.             (goto-char (+ from max-size))
  862.             (re-search-forward "\^_" nil 'mv)
  863.             (rmail-decode-coding-system from (point)))))
  864.            (t
  865.             ;; Perhaps, MMDF format.  Since I don't know how to
  866.             ;; deal with it, convert all data at once.
  867.             (rmail-decode-coding-system (point) (point-max))))))
  868.         (goto-char (point-max))
  869.         (or (= (preceding-char) ?\n)
  870.         (zerop size)
  871.         (insert ?\n))
  872.         (setq delete-files (cons tofile delete-files))))
  873.       (message "")
  874.       (setq files (cdr files)))
  875.     delete-files))
  876.  
  877. (if (not (featurep 'mule)) nil
  878.  
  879. (defvar mail-coding-system '*junet*)
  880.  
  881. (defun rmail-decode-coding-system (from to)
  882.   (let (coding-system)
  883.     ;; At first, detect the coding-system of the region and set it to
  884.     ;; `coding-sytem'.
  885.     (let ((detected-coding-system (code-detect-region from to))
  886.       (coding (get-code mail-coding-system)))
  887.       (if (listp detected-coding-system)
  888.       ;; Something other than ASCII was found.  If a coding-system
  889.       ;; of which information is same as `mail-coding-system' is
  890.       ;; in the list of detected coding-systems, use it, else use
  891.       ;; the coding-system of the highest priority in the list.
  892.       (let ((l detected-coding-system))
  893.         (while (and l
  894.             (null (eq (get-code (car l)) coding)))
  895.           (setq l (cdr l)))
  896.         (setq coding-system (car (or l detected-coding-system))))))
  897.     ;; Then, decode the region.
  898.     (if coding-system
  899.     (save-restriction
  900.       (narrow-to-region from to)
  901.       (code-convert from to coding-system '*internal*)
  902.       (goto-char (point-max))))))
  903.  
  904. ) ; (featurep 'mule)
  905.  
  906. ;; the  rmail-break-forwarded-messages  feature is not implemented
  907. (defun rmail-convert-to-babyl-format ()
  908.   (let ((count 0) start
  909.     (case-fold-search nil)
  910.     (invalid-input-resync
  911.      (function (lambda ()
  912.              (message "Invalid Babyl format in inbox!")
  913.              (sit-for 1)
  914.              ;; Try to get back in sync with a real message.
  915.              (if (re-search-forward
  916.               (concat mmdf-delim1 "\\|^From") nil t)
  917.              (beginning-of-line)
  918.                (goto-char (point-max)))))))
  919.     (goto-char (point-min))
  920.     (save-restriction
  921.       (while (not (eobp))
  922.     (cond ((looking-at "BABYL OPTIONS:");Babyl header
  923.            (if (search-forward "\n\^_" nil t)
  924.            ;; If we find the proper terminator, delete through there.
  925.            (delete-region (point-min) (point))
  926.          (funcall invalid-input-resync)
  927.          (delete-region (point-min) (point))))
  928.           ;; Babyl format message
  929.           ((looking-at "\^L")
  930.            (or (search-forward "\n\^_" nil t)
  931.            (funcall invalid-input-resync))
  932.            (setq count (1+ count))
  933.            ;; Make sure there is no extra white space after the ^_
  934.            ;; at the end of the message.
  935.            ;; Narrowing will make sure that whatever follows the junk
  936.            ;; will be treated properly.
  937.            (delete-region (point)
  938.                   (save-excursion
  939.                 (skip-chars-forward " \t\n")
  940.                 (point)))
  941.            (narrow-to-region (point) (point-max)))
  942.           ;;*** MMDF format
  943.           ((let ((case-fold-search t))
  944.          (looking-at mmdf-delim1))
  945.            (let ((case-fold-search t))
  946.          (replace-match "\^L\n0, unseen,,\n*** EOOH ***\n")
  947.          (setq start (point))
  948.          (re-search-forward mmdf-delim2 nil t)
  949.          (replace-match "\^_"))
  950.            (save-excursion
  951.          (save-restriction
  952.            (narrow-to-region start (1- (point)))
  953.            (goto-char (point-min))
  954.            (while (search-forward "\n\^_" nil t); single char "\^_"
  955.              (replace-match "\n^_")))); 2 chars: "^" and "_"
  956.            (narrow-to-region (point) (point-max))
  957.            (setq count (1+ count)))
  958.           ;;*** Mail format
  959.           ((looking-at "^From ")
  960.            (setq start (point))
  961.            (insert "\^L\n0, unseen,,\n*** EOOH ***\n")
  962.            (rmail-nuke-pinhead-header)
  963.            ;; If this message has a Content-Length field,
  964.            ;; skip to the end of the contents.
  965.            (let* ((header-end (save-excursion
  966.                     (and (re-search-forward "\n\n" nil t)
  967.                      (point))))
  968.               (case-fold-search t)
  969.               (size
  970.                ;; Get the numeric value from the Content-Length field.
  971.                (save-excursion
  972.              ;; Back up to end of prev line,
  973.              ;; in case the Content-Length field comes first.
  974.              (forward-char -1)
  975.              (and (search-forward "\ncontent-length: "
  976.                           header-end t)
  977.                   (let ((beg (point))
  978.                     (eol (progn (end-of-line) (point))))
  979.                 (read (buffer-substring beg eol)))))))
  980.          (and size (numberp size) (>= size 0)
  981.               (goto-char (+ header-end size))))
  982.  
  983.            (if (re-search-forward
  984.             (concat "^[\^_]?\\("
  985.                 rmail-unix-mail-delimiter
  986.                 "\\|"
  987.                 mmdf-delim1 "\\|"
  988.                 "^BABYL OPTIONS:\\|"
  989.                 "\^L\n[01],\\)") nil t)
  990.            (goto-char (match-beginning 1))
  991.          (goto-char (point-max)))
  992.            (setq count (1+ count))
  993.            (save-excursion
  994.          (save-restriction
  995.            (narrow-to-region start (point))
  996.            (goto-char (point-min))
  997.            (while (search-forward "\n\^_" nil t); single char
  998.              (replace-match "\n^_")))); 2 chars: "^" and "_"
  999.            (insert ?\^_)
  1000.            (narrow-to-region (point) (point-max)))
  1001.           ;;
  1002.           ;; This kludge is because some versions of sendmail.el
  1003.           ;; insert an extra newline at the beginning that shouldn't
  1004.           ;; be there.  sendmail.el has been fixed, but old versions
  1005.           ;; may still be in use.  -- rms, 7 May 1993.
  1006.           ((eolp) (delete-char 1))
  1007.           (t (error "Cannot convert to babyl format")))))
  1008.     count))
  1009.  
  1010. ;; Delete the "From ..." line, creating various other headers with
  1011. ;; information from it if they don't already exist.  Now puts the
  1012. ;; original line into a mail-from: header line for debugging and for
  1013. ;; use by the rmail-output function.
  1014. (defun rmail-nuke-pinhead-header ()
  1015.   (save-excursion
  1016.     (save-restriction
  1017.       (let ((start (point))
  1018.           (end (progn
  1019.            (condition-case ()
  1020.                (search-forward "\n\n")
  1021.              (error
  1022.               (goto-char (point-max))
  1023.               (insert "\n\n")))
  1024.            (point)))
  1025.         has-from has-date)
  1026.     (narrow-to-region start end)
  1027.     (let ((case-fold-search t))
  1028.       (goto-char start)
  1029.       (setq has-from (search-forward "\nFrom:" nil t))
  1030.       (goto-char start)
  1031.       (setq has-date (and (search-forward "\nDate:" nil t) (point)))
  1032.       (goto-char start))
  1033.     (let ((case-fold-search nil))
  1034.       (if (re-search-forward (concat "^" rmail-unix-mail-delimiter) nil t)
  1035.           (replace-match
  1036.         (concat
  1037.           "Mail-from: \\&"
  1038.           ;; Keep and reformat the date if we don't
  1039.           ;;  have a Date: field.
  1040.           (if has-date
  1041.               ""
  1042.             (concat
  1043.              "Date: \\3, \\5 \\4 \\9 \\6 "
  1044.             
  1045.              ;; The timezone could be matched by group 7 or group 10.
  1046.              ;; If neither of them matched, assume EST, since only
  1047.              ;; Easterners would be so sloppy.
  1048.              ;; It's a shame the substitution can't use "\\10".
  1049.              (cond
  1050.               ((/= (match-beginning 7) (match-end 7)) "\\7")
  1051.               ((/= (match-beginning 10) (match-end 10))
  1052.                (buffer-substring (match-beginning 10)
  1053.                      (match-end 10)))
  1054.               (t "EST"))
  1055.              "\n"))
  1056.           ;; Keep and reformat the sender if we don't
  1057.           ;; have a From: field.
  1058.           (if has-from
  1059.               ""
  1060.             "From: \\1\n"))
  1061.         t)))))))
  1062.  
  1063. ;;;; *** Rmail Message Formatting and Header Manipulation ***
  1064.  
  1065. (defun rmail-reformat-message (beg end)
  1066.   (goto-char beg)
  1067.   (forward-line 1)
  1068.   (if (/= (following-char) ?0)
  1069.       (error "Bad format in RMAIL file."))
  1070.   (let ((buffer-read-only nil)
  1071.     (delta (- (buffer-size) end)))
  1072.     (delete-char 1)
  1073.     (insert ?1)
  1074.     (forward-line 1)
  1075.     (let ((case-fold-search t))
  1076.       (while (looking-at "Summary-line:\\|Mail-From:")
  1077.      (forward-line 1)))
  1078.     (if (looking-at "\\*\\*\\* EOOH \\*\\*\\*\n")
  1079.     (delete-region (point)
  1080.                (progn (forward-line 1) (point))))
  1081.     (let ((str (buffer-substring (point)
  1082.                  (save-excursion (search-forward "\n\n" end 'move)
  1083.                          (point)))))
  1084.       (insert str "*** EOOH ***\n")
  1085.       (narrow-to-region (point) (- (buffer-size) delta)))
  1086.     (goto-char (point-min))
  1087.     (if rmail-ignored-headers (rmail-clear-headers))
  1088.     (if rmail-message-filter (funcall rmail-message-filter))))
  1089.  
  1090. (defun rmail-clear-headers ()
  1091.   (if (search-forward "\n\n" nil t)
  1092.       (save-restriction
  1093.         (narrow-to-region (point-min) (point))
  1094.     (let ((buffer-read-only nil))
  1095.       (while (let ((case-fold-search t))
  1096.            (goto-char (point-min))
  1097.            (re-search-forward rmail-ignored-headers nil t))
  1098.         (beginning-of-line)
  1099.         (delete-region (point)
  1100.                (progn (re-search-forward "\n[^ \t]")
  1101.                   (forward-char -1)
  1102.                   (point))))))))
  1103.  
  1104. (defun rmail-toggle-header ()
  1105.   "Show original message header if pruned header currently shown, or vice versa."
  1106.   (interactive)
  1107.   (rmail-maybe-set-message-counters)
  1108.   (narrow-to-region (rmail-msgbeg rmail-current-message) (point-max))
  1109.   (let ((buffer-read-only nil))
  1110.     (goto-char (point-min))
  1111.     (forward-line 1)
  1112.     (if (= (following-char) ?1)
  1113.     (progn (delete-char 1)
  1114.            (insert ?0)
  1115.            (forward-line 1)
  1116.            (let ((case-fold-search t))
  1117.           (while (looking-at "Summary-Line:\\|Mail-From:")
  1118.             (forward-line 1)))
  1119.            (insert "*** EOOH ***\n")
  1120.            (forward-char -1)
  1121.            (search-forward "\n*** EOOH ***\n")
  1122.            (forward-line -1)
  1123.            (let ((temp (point)))
  1124.          (and (search-forward "\n\n" nil t)
  1125.               (delete-region temp (point))))
  1126.            (goto-char (point-min))
  1127.            (search-forward "\n*** EOOH ***\n")
  1128.            (narrow-to-region (point) (point-max)))
  1129.       (rmail-reformat-message (point-min) (point-max)))))
  1130.  
  1131. ;;;; *** Rmail Attributes and Keywords ***
  1132.  
  1133. ;; Make a string describing current message's attributes and keywords
  1134. ;; and set it up as the name of a minor mode
  1135. ;; so it will appear in the mode line.
  1136. (defun rmail-display-labels ()
  1137.   (let ((blurb "") (beg (point-min-marker)) (end (point-max-marker)))
  1138.     (save-excursion
  1139.       (unwind-protect
  1140.       (progn
  1141.         (widen)
  1142.         (goto-char (rmail-msgbeg rmail-current-message))
  1143.         (forward-line 1)
  1144.         (if (looking-at "[01],")
  1145.         (progn
  1146.           (narrow-to-region (point) (progn (end-of-line) (point)))
  1147.           ;; Truly valid BABYL format requires a space before each
  1148.           ;; attribute or keyword name.  Put them in if missing.
  1149.           (let (buffer-read-only)
  1150.             (goto-char (point-min))
  1151.             (while (search-forward "," nil t)
  1152.               (or (looking-at "[ ,]") (eobp)
  1153.               (insert " "))))
  1154.           (goto-char (point-max))
  1155.           (if (search-backward ",," nil 'move)
  1156.               (progn
  1157.             (if (> (point) (1+ (point-min)))
  1158.                 (setq blurb (buffer-substring (+ 1 (point-min)) (point))))
  1159.             (if (> (- (point-max) (point)) 2)
  1160.                 (setq blurb
  1161.                   (concat blurb
  1162.                       ";"
  1163.                       (buffer-substring (+ (point) 3)
  1164.                                 (1- (point-max)))))))))))
  1165.     ;; Note: we don't use save-restriction because that does not work right
  1166.     ;; if changes are made outside the saved restriction
  1167.     ;; before that restriction is restored.
  1168.     (narrow-to-region beg end)
  1169.     (set-marker beg nil)
  1170.     (set-marker end nil)))
  1171.     (while (string-match " +," blurb)
  1172.       (setq blurb (concat (substring blurb 0 (match-beginning 0)) ","
  1173.               (substring blurb (match-end 0)))))
  1174.     (while (string-match ", +" blurb)
  1175.       (setq blurb (concat (substring blurb 0 (match-beginning 0)) ","
  1176.               (substring blurb (match-end 0)))))
  1177.     (setq mode-line-process
  1178.       (format " %d/%d%s" rmail-current-message rmail-total-messages
  1179.           blurb))))
  1180.  
  1181. ;; Turn an attribute of a message on or off according to STATE.
  1182. ;; ATTR is the name of the attribute, as a string.
  1183. ;; MSGNUM is message number to change; nil means current message.
  1184. (defun rmail-set-attribute (attr state &optional msgnum)
  1185.   (let ((omax (point-max-marker))
  1186.     (omin (point-min-marker))
  1187.     (buffer-read-only nil))
  1188.     (or msgnum (setq msgnum rmail-current-message))
  1189.     (if (> msgnum 0)
  1190.     (unwind-protect
  1191.         (save-excursion
  1192.           (widen)
  1193.           (goto-char (+ 3 (rmail-msgbeg msgnum)))
  1194.           (let ((curstate
  1195.              (not
  1196.               (null (search-backward (concat ", " attr ",")
  1197.                          (prog1 (point) (end-of-line)) t)))))
  1198.         (or (eq curstate (not (not state)))
  1199.             (if curstate
  1200.             (delete-region (point) (1- (match-end 0)))
  1201.               (beginning-of-line)
  1202.               (forward-char 2)
  1203.               (insert " " attr ","))))
  1204.           (if (string= attr "deleted")
  1205.           (rmail-set-message-deleted-p msgnum state)))
  1206.       ;; Note: we don't use save-restriction because that does not work right
  1207.       ;; if changes are made outside the saved restriction
  1208.       ;; before that restriction is restored.
  1209.       (narrow-to-region omin omax)
  1210.       (set-marker omin nil)
  1211.       (set-marker omax nil)
  1212.       (if (= msgnum rmail-current-message)
  1213.           (rmail-display-labels))))))
  1214.  
  1215. ;; Return t if the attributes/keywords line of msg number MSG
  1216. ;; contains a match for the regexp LABELS.
  1217. (defun rmail-message-labels-p (msg labels)
  1218.   (save-excursion
  1219.     (save-restriction
  1220.       (widen)
  1221.       (goto-char (rmail-msgbeg msg))
  1222.       (forward-char 3)
  1223.       (re-search-backward labels (prog1 (point) (end-of-line)) t))))
  1224.  
  1225. ;;;; *** Rmail Message Selection And Support ***
  1226.  
  1227. (defun rmail-msgend (n)
  1228.   (marker-position (aref rmail-message-vector (1+ n))))
  1229.  
  1230. (defun rmail-msgbeg (n)
  1231.   (marker-position (aref rmail-message-vector n)))
  1232.  
  1233. (defun rmail-widen-to-current-msgbeg (function)
  1234.   "Call FUNCTION with point at start of internal data of current message.
  1235. Assumes that bounds were previously narrowed to display the message in Rmail.
  1236. The bounds are widened enough to move point where desired, then narrowed
  1237. again afterward.
  1238.  
  1239. FUNCTION may not change the visible text of the message, but it may
  1240. change the invisible header text."
  1241.   (save-excursion
  1242.     (let ((obeg (- (point-max) (point-min))))
  1243.       (unwind-protect
  1244.       (progn
  1245.         (narrow-to-region (rmail-msgbeg rmail-current-message)
  1246.                   (point-max))
  1247.         (goto-char (point-min))
  1248.         (funcall function))
  1249.     ;; Note: we don't use save-restriction because that does not work right
  1250.     ;; if changes are made outside the saved restriction
  1251.     ;; before that restriction is restored.
  1252.     ;; Here we assume that changes made by FUNCTION
  1253.     ;; occur before the visible region of the message.
  1254.     (narrow-to-region (- (point-max) obeg) (point-max))))))
  1255.  
  1256. (defun rmail-forget-messages ()
  1257.   (unwind-protect
  1258.       (if (vectorp rmail-message-vector)
  1259.       (let* ((i 0)
  1260.          (v rmail-message-vector)
  1261.          (n (length v)))
  1262.         (while (< i n)
  1263.           (move-marker (aref v i)  nil)
  1264.           (setq i (1+ i)))))
  1265.     (setq rmail-message-vector nil)
  1266.     (setq rmail-deleted-vector nil)))
  1267.  
  1268. (defun rmail-maybe-set-message-counters ()
  1269.   (if (not (and rmail-deleted-vector
  1270.         rmail-message-vector
  1271.         rmail-current-message
  1272.         rmail-total-messages))
  1273.       (rmail-set-message-counters)))
  1274.  
  1275. (defun rmail-count-new-messages (&optional nomsg)
  1276.   (let* ((case-fold-search nil)
  1277.      (total-messages 0)
  1278.      (messages-head nil)
  1279.      (deleted-head nil))
  1280.     (or nomsg (message "Counting new messages..."))
  1281.     (goto-char (point-max))
  1282.     ;; Put at the end of messages-head
  1283.     ;; the entry for message N+1, which marks
  1284.     ;; the end of message N.  (N = number of messages).
  1285.     (search-backward "\n\^_")
  1286.     (forward-char 1)
  1287.     (setq messages-head (list (point-marker)))
  1288.     (rmail-set-message-counters-counter (point-min))
  1289.     (setq rmail-current-message (1+ rmail-total-messages))
  1290.     (setq rmail-total-messages
  1291.       (+ rmail-total-messages total-messages))
  1292.     (setq rmail-message-vector
  1293.       (vconcat rmail-message-vector (cdr messages-head)))
  1294.     (aset rmail-message-vector
  1295.       rmail-current-message (car messages-head))
  1296.     (setq rmail-deleted-vector
  1297.       (concat rmail-deleted-vector deleted-head))
  1298.     (setq rmail-summary-vector
  1299.       (vconcat rmail-summary-vector (make-vector total-messages nil)))
  1300.     (goto-char (point-min))
  1301.     (or nomsg (message "Counting new messages...done (%d)" total-messages))))
  1302.  
  1303. (defun rmail-set-message-counters ()
  1304.   (rmail-forget-messages)
  1305.   (save-excursion
  1306.     (save-restriction
  1307.       (widen)
  1308.       (let* ((point-save (point))
  1309.          (total-messages 0)
  1310.          (messages-after-point)
  1311.          (case-fold-search nil)
  1312.          (messages-head nil)
  1313.          (deleted-head nil))
  1314.     (message "Counting messages...")
  1315.     (goto-char (point-max))
  1316.     ;; Put at the end of messages-head
  1317.     ;; the entry for message N+1, which marks
  1318.     ;; the end of message N.  (N = number of messages).
  1319.     (search-backward "\n\^_")
  1320.     (forward-char 1)
  1321.     (setq messages-head (list (point-marker)))
  1322.     (rmail-set-message-counters-counter (min (point) point-save))
  1323.     (setq messages-after-point total-messages)
  1324.     (rmail-set-message-counters-counter)
  1325.     (setq rmail-total-messages total-messages)
  1326.     (setq rmail-current-message
  1327.           (min total-messages
  1328.            (max 1 (- total-messages messages-after-point))))
  1329.     (setq rmail-message-vector
  1330.           (apply 'vector (cons (point-min-marker) messages-head))
  1331.           rmail-deleted-vector (concat "D" deleted-head)
  1332.           rmail-summary-vector (make-vector rmail-total-messages nil))
  1333.     (message "Counting messages...done")))))
  1334.     
  1335. (defun rmail-set-message-counters-counter (&optional stop)
  1336.   (while (search-backward "\n\^_\^L\n" stop t)
  1337.     (forward-char 1)
  1338.     (setq messages-head (cons (point-marker) messages-head))
  1339.     (save-excursion
  1340.       (setq deleted-head
  1341.         (cons (if (search-backward ", deleted,"
  1342.                        (prog1 (point)
  1343.                      (forward-line 2))
  1344.                        t)
  1345.               ?D ?\ )
  1346.           deleted-head)))
  1347.     (if (zerop (% (setq total-messages (1+ total-messages)) 20))
  1348.     (message "Counting messages...%d" total-messages))))
  1349.  
  1350. (defun rmail-beginning-of-message ()
  1351.   "Show current message starting from the beginning."
  1352.   (interactive)
  1353.   (rmail-show-message rmail-current-message))
  1354.  
  1355. (defun rmail-show-message (&optional n)
  1356.   "Show message number N (prefix argument), counting from start of file.
  1357. If summary buffer is currently displayed, update current message there also."
  1358.   (interactive "p")
  1359.   (rmail-maybe-set-message-counters)
  1360.   (widen)
  1361.   (if (zerop rmail-total-messages)
  1362.       (progn (narrow-to-region (point-min) (1- (point-max)))
  1363.          (goto-char (point-min))
  1364.          (setq mode-line-process nil))
  1365.     (let (blurb)
  1366.       (if (not n)
  1367.       (setq n rmail-current-message)
  1368.     (cond ((<= n 0)
  1369.            (setq n 1
  1370.              rmail-current-message 1
  1371.              blurb "No previous message"))
  1372.           ((> n rmail-total-messages)
  1373.            (setq n rmail-total-messages
  1374.              rmail-current-message rmail-total-messages
  1375.              blurb "No following message"))
  1376.           (t
  1377.            (setq rmail-current-message n))))
  1378.       (let ((beg (rmail-msgbeg n))
  1379.         (end (rmail-msgend n)))
  1380.     (goto-char beg)
  1381.     (forward-line 1)
  1382.     (if (= (following-char) ?0)
  1383.         (progn
  1384.           (rmail-reformat-message beg end)
  1385.           (rmail-set-attribute "unseen" nil))
  1386.       (search-forward "\n*** EOOH ***\n" end t)
  1387.       (narrow-to-region (point) end))
  1388.     (goto-char (point-min))
  1389.     (rmail-display-labels)
  1390.     (run-hooks 'rmail-show-message-hook)
  1391.     ;; If there is a summary buffer, try to move to this message
  1392.     ;; in that buffer.  But don't complain if this message
  1393.     ;; is not mentioned in the summary.
  1394.     (if (rmail-summary-exists)
  1395.         (let ((curr-msg rmail-current-message))
  1396.           (rmail-select-summary
  1397.            (rmail-summary-goto-msg curr-msg t t))))
  1398.     (if blurb
  1399.         (message blurb))))))
  1400.  
  1401. (defun rmail-next-message (n)
  1402.   "Show following message whether deleted or not.
  1403. With prefix arg N, moves forward N messages, or backward if N is negative."
  1404.   (interactive "p")
  1405.   (rmail-maybe-set-message-counters)
  1406.   (rmail-show-message (+ rmail-current-message n)))
  1407.  
  1408. (defun rmail-previous-message (n)
  1409.   "Show previous message whether deleted or not.
  1410. With prefix arg N, moves backward N messages, or forward if N is negative."
  1411.   (interactive "p")
  1412.   (rmail-next-message (- n)))  
  1413.  
  1414. (defun rmail-next-undeleted-message (n)
  1415.   "Show following non-deleted message.
  1416. With prefix arg N, moves forward N non-deleted messages,
  1417. or backward if N is negative.
  1418.  
  1419. Returns t if a new message is being shown, nil otherwise."
  1420.   (interactive "p")
  1421.   (rmail-maybe-set-message-counters)
  1422.   (let ((lastwin rmail-current-message)
  1423.     (current rmail-current-message))
  1424.     (while (and (> n 0) (< current rmail-total-messages))
  1425.       (setq current (1+ current))
  1426.       (if (not (rmail-message-deleted-p current))
  1427.       (setq lastwin current n (1- n))))
  1428.     (while (and (< n 0) (> current 1))
  1429.       (setq current (1- current))
  1430.       (if (not (rmail-message-deleted-p current))
  1431.       (setq lastwin current n (1+ n))))
  1432.     (if (/= lastwin rmail-current-message)
  1433.      (progn (rmail-show-message lastwin)
  1434.             t)
  1435.       (if (< n 0)
  1436.       (message "No previous nondeleted message"))
  1437.       (if (> n 0)
  1438.       (message "No following nondeleted message"))
  1439.       nil)))
  1440.  
  1441. (defun rmail-previous-undeleted-message (n)
  1442.   "Show previous non-deleted message.
  1443. With prefix argument N, moves backward N non-deleted messages,
  1444. or forward if N is negative."
  1445.   (interactive "p")
  1446.   (rmail-next-undeleted-message (- n)))
  1447.  
  1448. (defun rmail-first-message ()
  1449.   "Show first message in file."
  1450.   (interactive)
  1451.   (rmail-maybe-set-message-counters)
  1452.   (rmail-show-message 1))
  1453.  
  1454. (defun rmail-last-message ()
  1455.   "Show last message in file."
  1456.   (interactive)
  1457.   (rmail-maybe-set-message-counters)
  1458.   (rmail-show-message rmail-total-messages))
  1459.  
  1460. (defun rmail-what-message ()
  1461.   (let ((where (point))
  1462.     (low 1)
  1463.     (high rmail-total-messages)
  1464.     (mid (/ rmail-total-messages 2)))
  1465.     (while (> (- high low) 1)
  1466.       (if (>= where (rmail-msgbeg mid))
  1467.       (setq low mid)
  1468.     (setq high mid))
  1469.       (setq mid (+ low (/ (- high low) 2))))
  1470.     (if (>= where (rmail-msgbeg high)) high low)))
  1471.  
  1472. (defun rmail-message-recipients-p (msg recipients &optional primary-only)
  1473.   (save-restriction
  1474.     (goto-char (rmail-msgbeg msg))
  1475.     (search-forward "\n*** EOOH ***\n")
  1476.     (narrow-to-region (point) (progn (search-forward "\n\n") (point)))
  1477.     (or (string-match recipients (or (mail-fetch-field "To") ""))
  1478.     (string-match recipients (or (mail-fetch-field "From") ""))
  1479.     (if (not primary-only)
  1480.         (string-match recipients (or (mail-fetch-field "Cc") ""))))))
  1481.  
  1482. (defun rmail-message-regexp-p (msg regexp)
  1483.   "Return t, if for message number MSG, regexp REGEXP matches in the header."
  1484.   (goto-char (rmail-msgbeg msg))
  1485.   (let ((end 
  1486.          (save-excursion 
  1487.            (search-forward "*** EOOH ***" (point-max)) (point))))
  1488.     (re-search-forward regexp end t)))
  1489.  
  1490. (defvar rmail-search-last-regexp nil) ; jwz: moved this up
  1491. (defun rmail-search-backward (regexp &optional n)
  1492.   "Show message containing next match for REGEXP.
  1493. Prefix argument gives repeat count; negative argument means search
  1494. backwards (through earlier messages).
  1495. Interactively, empty argument means use same regexp used last time."
  1496.   (interactive
  1497.     (let* ((reversep (>= (prefix-numeric-value current-prefix-arg) 0))
  1498.        (prompt
  1499.         (concat (if reversep "Reverse " "") "Rmail search (regexp): "))
  1500.        regexp)
  1501.       (if rmail-search-last-regexp
  1502.       (setq prompt (concat prompt
  1503.                    "(default "
  1504.                    rmail-search-last-regexp
  1505.                    ") ")))
  1506.       (setq regexp (read-string prompt))
  1507.       (cond ((not (equal regexp ""))
  1508.          (setq rmail-search-last-regexp regexp))
  1509.         ((not rmail-search-last-regexp)
  1510.          (error "No previous Rmail search string")))
  1511.       (list rmail-search-last-regexp
  1512.         (prefix-numeric-value current-prefix-arg))))
  1513.   (rmail-search regexp (- n)))
  1514.  
  1515. (defun rmail-search (regexp &optional n)
  1516.   "Show message containing next match for REGEXP.
  1517. Prefix argument gives repeat count; negative argument means search
  1518. backwards (through earlier messages).
  1519. Interactively, empty argument means use same regexp used last time."
  1520.   (interactive
  1521.     (let* ((reversep (< (prefix-numeric-value current-prefix-arg) 0))
  1522.        (prompt
  1523.         (concat (if reversep "Reverse " "") "Rmail search (regexp): "))
  1524.        regexp)
  1525.       (if rmail-search-last-regexp
  1526.       (setq prompt (concat prompt
  1527.                    "(default "
  1528.                    rmail-search-last-regexp
  1529.                    ") ")))
  1530.       (setq regexp (read-string prompt))
  1531.       (cond ((not (equal regexp ""))
  1532.          (setq rmail-search-last-regexp regexp))
  1533.         ((not rmail-search-last-regexp)
  1534.          (error "No previous Rmail search string")))
  1535.       (list rmail-search-last-regexp
  1536.         (prefix-numeric-value current-prefix-arg))))
  1537.   (or n (setq n 1))
  1538.   (message "%sRmail search for %s..."
  1539.        (if (< n 0) "Reverse " "")
  1540.        regexp)
  1541.   (rmail-maybe-set-message-counters)
  1542.   (let ((omin (point-min))
  1543.     (omax (point-max))
  1544.     (opoint (point))
  1545.     win
  1546.     (reversep (< n 0))
  1547.     (msg rmail-current-message))
  1548.     (unwind-protect
  1549.     (progn
  1550.       (widen)
  1551.       (while (/= n 0)
  1552.         ;; Check messages one by one, advancing message number up or down
  1553.         ;; but searching forward through each message.
  1554.         (if reversep
  1555.         (while (and (null win) (> msg 1))
  1556.           (goto-char (rmail-msgbeg (setq msg (1- msg))))
  1557.           (setq win (re-search-forward
  1558.                  regexp (rmail-msgend msg) t)))
  1559.           (while (and (null win) (< msg rmail-total-messages))
  1560.         (goto-char (rmail-msgbeg (setq msg (1+ msg))))
  1561.         (setq win (re-search-forward regexp (rmail-msgend msg) t))))
  1562.         (setq n (+ n (if reversep 1 -1)))))
  1563.       (if win
  1564.       (progn
  1565.         ;; If this is a reverse search and we found a message,
  1566.         ;; search backward thru this message to position point.
  1567.         (if reversep
  1568.         (progn
  1569.           (goto-char (rmail-msgend msg))
  1570.           (re-search-backward
  1571.            regexp (rmail-msgbeg msg) t)))
  1572.         (setq win (point))
  1573.         (rmail-show-message msg)
  1574.         (message "%sRmail search for %s...done"
  1575.              (if reversep "Reverse " "")
  1576.              regexp)
  1577.         (goto-char win))
  1578.     (goto-char opoint)
  1579.     (narrow-to-region omin omax)
  1580.     (ding)
  1581.     (message "Search failed: %s" regexp)))))
  1582.  
  1583. (defun rmail-search-backwards (regexp &optional n)
  1584.   "Show message containing previous match for REGEXP.
  1585. Prefix argument gives repeat count; negative argument means search
  1586. forward (through later messages).
  1587. Interactively, empty argument means use same regexp used last time."
  1588.   (interactive
  1589.     (let* ((reversep (>= (prefix-numeric-value current-prefix-arg) 0))
  1590.        (prompt
  1591.         (concat (if reversep "Reverse " "") "Rmail search (regexp): "))
  1592.        regexp)
  1593.       (if rmail-search-last-regexp
  1594.       (setq prompt (concat prompt
  1595.                    "(default "
  1596.                    rmail-search-last-regexp
  1597.                    ") ")))
  1598.       (setq regexp (read-string prompt))
  1599.       (cond ((not (equal regexp ""))
  1600.          (setq rmail-search-last-regexp regexp))
  1601.         ((not rmail-search-last-regexp)
  1602.          (error "No previous Rmail search string")))
  1603.       (list rmail-search-last-regexp
  1604.         (prefix-numeric-value current-prefix-arg))))
  1605.   (rmail-search regexp (- (or n -1))))
  1606.  
  1607. ;; Show the first message which has the `unseen' attribute.
  1608. (defun rmail-first-unseen-message ()
  1609.   (rmail-maybe-set-message-counters)
  1610.   (let ((current 1)
  1611.     found)
  1612.     (save-restriction
  1613.       (widen)
  1614.       (while (and (not found) (< current rmail-total-messages))
  1615.     (if (rmail-message-labels-p current ", ?\\(unseen\\),")
  1616.         (setq found current))
  1617.     (setq current (1+ current))))
  1618. ;; Let the caller show the message.
  1619. ;;    (if found
  1620. ;;    (rmail-show-message found))
  1621.     found))
  1622.  
  1623. ;;;; *** Rmail Message Deletion Commands ***
  1624.  
  1625. (defun rmail-message-deleted-p (n)
  1626.   (= (aref rmail-deleted-vector n) ?D))
  1627.  
  1628. (defun rmail-set-message-deleted-p (n state)
  1629.   (aset rmail-deleted-vector n (if state ?D ?\ )))
  1630.  
  1631. (defun rmail-delete-message ()
  1632.   "Delete this message and stay on it."
  1633.   (interactive)
  1634.   (rmail-set-attribute "deleted" t))
  1635.  
  1636. (defun rmail-undelete-previous-message ()
  1637.   "Back up to deleted message, select it, and undelete it."
  1638.   (interactive)
  1639.   (let ((msg rmail-current-message))
  1640.     (while (and (> msg 0)
  1641.         (not (rmail-message-deleted-p msg)))
  1642.       (setq msg (1- msg)))
  1643.     (if (= msg 0)
  1644.     (error "No previous deleted message")
  1645.       (if (/= msg rmail-current-message)
  1646.       (rmail-show-message msg))
  1647.       (rmail-set-attribute "deleted" nil)
  1648.       (if (rmail-summary-exists)
  1649.       (save-excursion
  1650.         (set-buffer rmail-summary-buffer)
  1651.         (rmail-summary-mark-undeleted msg)))
  1652.       (rmail-maybe-display-summary))))
  1653.  
  1654. (defun rmail-delete-forward (&optional backward)
  1655.   "Delete this message and move to next nondeleted one.
  1656. Deleted messages stay in the file until the \\[rmail-expunge] command is given.
  1657. With prefix argument, delete and move backward.
  1658.  
  1659. Returns t if a new message is displayed after the delete, or nil otherwise."
  1660.   (interactive "P")
  1661.   (rmail-set-attribute "deleted" t)
  1662.   (let ((del-msg rmail-current-message))
  1663.     (if (rmail-summary-exists)
  1664.     (save-excursion
  1665.       (set-buffer rmail-summary-buffer)
  1666.       (rmail-summary-mark-deleted del-msg)))
  1667.     (prog1 (rmail-next-undeleted-message (if backward -1 1))
  1668.       (rmail-maybe-display-summary))))
  1669.  
  1670. (defun rmail-delete-backward ()
  1671.   "Delete this message and move to previous nondeleted one.
  1672. Deleted messages stay in the file until the \\[rmail-expunge] command is given."
  1673.   (interactive)
  1674.   (rmail-delete-forward t))
  1675.  
  1676. (defun rmail-only-expunge ()
  1677.   "Actually erase all deleted messages in the file."
  1678.   (interactive)
  1679.   (message "Expunging deleted messages...")
  1680.   ;; Discard all undo records for this buffer.
  1681.   (or (eq buffer-undo-list t)
  1682.       (setq buffer-undo-list nil))
  1683.   (rmail-maybe-set-message-counters)
  1684.   (let* ((omax (- (buffer-size) (point-max)))
  1685.      (omin (- (buffer-size) (point-min)))
  1686.      (opoint (if (and (> rmail-current-message 0)
  1687.               (= ?D (aref rmail-deleted-vector rmail-current-message)))
  1688.              0 (- (point) (point-min))))
  1689.      (messages-head (cons (aref rmail-message-vector 0) nil))
  1690.      (messages-tail messages-head)
  1691.      ;; Don't make any undo records for the expunging.
  1692.      (buffer-undo-list t)
  1693.      (win))
  1694.     (unwind-protect
  1695.     (save-excursion
  1696.       (widen)
  1697.       (goto-char (point-min))
  1698.       (let ((counter 0)
  1699.         (number 1)
  1700.         (total rmail-total-messages)
  1701.         (new-message-number rmail-current-message)
  1702.         (new-summary nil)
  1703.         (buffer-read-only nil)
  1704.         (messages rmail-message-vector)
  1705.         (deleted rmail-deleted-vector)
  1706.         (summary rmail-summary-vector))
  1707.         (setq rmail-total-messages nil
  1708.           rmail-current-message nil
  1709.           rmail-message-vector nil
  1710.           rmail-deleted-vector nil
  1711.           rmail-summary-vector nil)
  1712.         (while (<= number total)
  1713.           (if (= (aref deleted number) ?D)
  1714.           (progn
  1715.             (delete-region
  1716.               (marker-position (aref messages number))
  1717.               (marker-position (aref messages (1+ number))))
  1718.             (move-marker (aref messages number) nil)
  1719.             (if (> new-message-number counter)
  1720.             (setq new-message-number (1- new-message-number))))
  1721.         (setq counter (1+ counter))
  1722.         (setq messages-tail
  1723.               (setcdr messages-tail
  1724.                   (cons (aref messages number) nil)))
  1725.         (setq new-summary
  1726.               (cons (if (= counter number) (aref summary (1- number)))
  1727.                 new-summary)))
  1728.           (if (zerop (% (setq number (1+ number)) 20))
  1729.           (message "Expunging deleted messages...%d" number)))
  1730.         (setq messages-tail
  1731.           (setcdr messages-tail
  1732.               (cons (aref messages number) nil)))
  1733.         (setq rmail-current-message new-message-number
  1734.           rmail-total-messages counter
  1735.           rmail-message-vector (apply 'vector messages-head)
  1736.           rmail-deleted-vector (make-string (1+ counter) ?\ )
  1737.           rmail-summary-vector (vconcat (nreverse new-summary))
  1738.           win t)))
  1739.       (message "Expunging deleted messages...done")
  1740.       (if (not win)
  1741.       (narrow-to-region (- (buffer-size) omin) (- (buffer-size) omax)))
  1742.       (rmail-show-message
  1743.        (if (zerop rmail-current-message) 1 nil))
  1744.       (forward-char opoint))))
  1745.  
  1746. (defun rmail-expunge ()
  1747.   "Erase deleted messages from Rmail file and summary buffer."
  1748.   (interactive)
  1749.   (rmail-only-expunge)
  1750.   (if (rmail-summary-exists)
  1751.       (rmail-select-summary
  1752.     (rmail-update-summary))))
  1753.  
  1754. ;;;; *** Rmail Mailing Commands ***
  1755.  
  1756. (defun rmail-start-mail (&rest args)
  1757.   (if (and window-system rmail-mail-new-frame)
  1758.       (prog1
  1759.     (apply 'mail-other-frame args)
  1760.     (modify-frame-parameters (selected-frame)
  1761.                  '((dedicated . t))))
  1762.     (apply 'mail-other-window args)))
  1763.  
  1764. (defun rmail-mail ()
  1765.   "Send mail in another window.
  1766. While composing the message, use \\[mail-yank-original] to yank the
  1767. original message into it."
  1768.   (interactive)
  1769.   (rmail-start-mail nil nil nil nil nil (current-buffer)))
  1770.  
  1771. (defun rmail-continue ()
  1772.   "Continue composing outgoing message previously being composed."
  1773.   (interactive)
  1774.   (rmail-start-mail t))
  1775.  
  1776. (defun rmail-reply (just-sender)
  1777.   "Reply to the current message.
  1778. Normally include CC: to all other recipients of original message;
  1779. prefix argument means ignore them.  While composing the reply,
  1780. use \\[mail-yank-original] to yank the original message into it."
  1781.   (interactive "P")
  1782.   (let (from reply-to cc subject date to message-id resent-reply-to)
  1783.     (save-excursion
  1784.       (save-restriction
  1785.     (widen)
  1786.     (goto-char (rmail-msgbeg rmail-current-message))
  1787.     (forward-line 1)
  1788.     (if (= (following-char) ?0)
  1789.         (narrow-to-region
  1790.          (progn (forward-line 2)
  1791.             (point))
  1792.          (progn (search-forward "\n\n" (rmail-msgend rmail-current-message)
  1793.                     'move)
  1794.             (point)))
  1795.       (narrow-to-region (point)
  1796.                 (progn (search-forward "\n*** EOOH ***\n")
  1797.                    (beginning-of-line) (point))))
  1798.     (setq resent-reply-to (mail-fetch-field "resent-reply-to" t)
  1799.           from (mail-fetch-field "from")
  1800.           reply-to (or resent-reply-to
  1801.                (mail-fetch-field "reply-to" nil t)
  1802.                from)
  1803.           cc (cond (just-sender nil)
  1804.                (resent-reply-to (mail-fetch-field "resent-cc" t))
  1805.                (t (mail-fetch-field "cc" nil t)))
  1806.           subject (or (and resent-reply-to
  1807.                    (mail-fetch-field "resent-subject" t))
  1808.               (mail-fetch-field "subject"))
  1809.           date (cond (resent-reply-to
  1810.               (mail-fetch-field "resent-date" t))
  1811.              ((mail-fetch-field "date")))
  1812.           to (cond (resent-reply-to
  1813.             (mail-fetch-field "resent-to" t))
  1814.                ((mail-fetch-field "to" nil t))
  1815.                ;((mail-fetch-field "apparently-to")) ack gag barf
  1816.                (t ""))
  1817.           message-id (cond (resent-reply-to
  1818.                 (mail-fetch-field "resent-message-id" t))
  1819.                    ((mail-fetch-field "message-id"))))))
  1820.     (and (stringp subject)
  1821.      (or (string-match (concat "\\`" (regexp-quote rmail-reply-prefix))
  1822.                subject)
  1823.          (setq subject (concat rmail-reply-prefix subject))))
  1824.     (rmail-start-mail nil
  1825.       (mail-strip-quoted-names reply-to)
  1826.       subject
  1827.       (rmail-make-in-reply-to-field from date message-id)
  1828.       (if just-sender
  1829.       nil
  1830.     (let* ((cc-list (rmail-dont-reply-to
  1831.               (mail-strip-quoted-names
  1832.                 (if (null cc) to (concat to ", " cc))))))
  1833.       (if (string= cc-list "") nil cc-list)))
  1834.       (current-buffer)
  1835.       (list (list '(lambda (buf msgnum)
  1836.              (save-excursion
  1837.                (set-buffer buf)
  1838.                (rmail-set-attribute "answered" t msgnum)))
  1839.           (current-buffer) rmail-current-message)))))
  1840.  
  1841. (defun rmail-make-in-reply-to-field (from date message-id)
  1842.   (cond ((not from)
  1843.          (if message-id
  1844.              message-id
  1845.              nil))
  1846.         (mail-use-rfc822
  1847.          (require 'rfc822)
  1848.          (let ((tem (car (rfc822-addresses from))))
  1849.            (if message-id
  1850.                (if (string-match
  1851.                     (regexp-quote (if (string-match "@[^@]*\\'" tem)
  1852.                                       (substring tem 0 (match-beginning 0))
  1853.                                       tem))
  1854.                     message-id)
  1855.                    ;; Message-ID is sufficiently informative
  1856.                    message-id
  1857.                    (concat message-id " (" tem ")"))
  1858.                ;; Use prin1 to fake RFC822 quoting
  1859.                (let ((field (prin1-to-string tem)))
  1860.                  (if date
  1861.                      (concat field "'s message of " date)
  1862.                      field)))))
  1863.         ((let* ((foo "[^][\000-\037\177-\377()<>@,;:\\\" ]+")
  1864.                 (bar "[^][\000-\037\177-\377()<>@,;:\\\"]+"))
  1865.            ;; Can't use format because format loses on \000 (unix *^&%*^&%$!!)
  1866.            (or (string-match (concat "\\`[ \t]*\\(" bar
  1867.                                      "\\)\\(<" foo "@" foo ">\\)?[ \t]*\\'")
  1868.                              ;; "Unix Loser <Foo@bar.edu>" => "Unix Loser"
  1869.                              from)
  1870.                (string-match (concat "\\`[ \t]*<" foo "@" foo ">[ \t]*(\\("
  1871.                                      bar "\\))[ \t]*\\'")
  1872.                              ;; "<Bugs@bar.edu>" (Losing Unix) => "Losing Unix"
  1873.                              from)))
  1874.          (let ((start (match-beginning 1))
  1875.                (end (match-end 1)))
  1876.            ;; Trim whitespace which above regexp match allows
  1877.            (while (and (< start end)
  1878.                        (memq (aref from start) '(?\t ?\ )))
  1879.              (setq start (1+ start)))
  1880.            (while (and (< start end)
  1881.                        (memq (aref from (1- end)) '(?\t ?\ )))
  1882.              (setq end (1- end)))
  1883.            (let ((field (substring from start end)))
  1884.              (if date (setq field (concat "message from " field " on " date)))
  1885.              (if message-id
  1886.                  ;; "<AA259@bar.edu> (message from Unix Loser on 1-Apr-89)"
  1887.                  (concat message-id " (" field ")")
  1888.                  field))))
  1889.         (t
  1890.          ;; If we can't kludge it simply, do it correctly
  1891.          (let ((mail-use-rfc822 t))
  1892.            (rmail-make-in-reply-to-field from date message-id)))))
  1893.  
  1894. (defun rmail-forward (resend)
  1895.   "Forward the current message to another user.
  1896. With prefix argument, \"resend\" the message instead of forwarding it;
  1897. see the documentation of `rmail-resend'."
  1898.   (interactive "P")
  1899.   (if resend
  1900.       (call-interactively 'rmail-resend)
  1901.     (let ((forward-buffer (current-buffer))
  1902.       (subject (concat "["
  1903.                (let ((from (or (mail-fetch-field "From")
  1904.                        (mail-fetch-field ">From"))))
  1905.                  (if from
  1906.                  (concat (mail-strip-quoted-names from) ": ")
  1907.                    ""))
  1908.                (or (mail-fetch-field "Subject") "")
  1909.                "]")))
  1910.       ;; If only one window, use it for the mail buffer.
  1911.       ;; Otherwise, use another window for the mail buffer
  1912.       ;; so that the Rmail buffer remains visible
  1913.       ;; and sending the mail will get back to it.
  1914.       (if (funcall (if (and (not rmail-mail-new-frame) (one-window-p t))
  1915.                (function mail)
  1916.              (function rmail-start-mail))
  1917.            nil nil subject nil nil nil
  1918.            (list (list (function (lambda (buf msgnum)
  1919.                        (save-excursion
  1920.                          (set-buffer buf)
  1921.                          (rmail-set-attribute
  1922.                           "forwarded" t msgnum))))
  1923.                    (current-buffer)
  1924.                    rmail-current-message)))
  1925.       (save-excursion
  1926.         ;; Insert after header separator--before signature if any.
  1927.         (goto-char (point-min))
  1928.         (search-forward-regexp
  1929.          (concat "^" (regexp-quote mail-header-separator)))
  1930.         (forward-line 1)
  1931.         (insert-buffer forward-buffer))))))
  1932.  
  1933. (defun rmail-resend (address &optional from comment mail-alias-file)
  1934.   "Resend current message to ADDRESSES.
  1935. ADDRESSES should be a single address, a a string consisting of several
  1936. addresses separated by commas, or a list of addresses.
  1937.  
  1938. Optional FROM is the address to resend the message from, and
  1939. defaults to the username of the person redistributing the message.
  1940. Optional COMMENT is a string that will be inserted as a comment in the
  1941. resent message.
  1942. Optional ALIAS-FILE is alternate aliases file to be used by sendmail,
  1943. typically for purposes of moderating a list."
  1944.   (interactive "sResend to: ")
  1945.   (require 'sendmail)
  1946.   ;;(require 'mailalias)
  1947.   (if (not from) (setq from (user-login-name)))
  1948.   (let ((tembuf (generate-new-buffer " sendmail temp"))
  1949.     (mail-header-separator "")
  1950.     (case-fold-search nil)
  1951.     (mailbuf (current-buffer)))
  1952.     (unwind-protect
  1953.     (save-excursion
  1954.       ;;>> Copy message into temp buffer
  1955.       (set-buffer tembuf)
  1956.       (insert-buffer-substring mailbuf)
  1957.       (goto-char (point-min))
  1958.       ;; Delete any Sender field, since that's not specifyable.
  1959.       (if (re-search-forward "^Sender:" nil t)
  1960.           (let (beg)
  1961.         (beginning-of-line)
  1962.         (setq beg (point))
  1963.         (forward-line 1)
  1964.         (while (looking-at "[ \t]")
  1965.           (forward-line 1))
  1966.         (delete-region beg (point))))
  1967.       ;;>> Insert resent-from:
  1968.       (insert "Resent-From: " from "\n")
  1969.       (insert "Resent-Date: " (mail-rfc822-date) "\n")
  1970.       ;;>> Insert resent-to: and bcc if need be.
  1971.       (progn ;;let ((before (point)))
  1972.         (if mail-self-blind
  1973.         (insert "Resent-Bcc: " (user-login-name) "\n"))
  1974.         (insert "Resent-To: " (if (stringp address)
  1975.                    address
  1976.                  (mapconcat 'identity address ",\n\t"))
  1977.             "\n")
  1978.         ;; lose this loser. -jwz
  1979.         ;;(expand-mail-aliases before (point))
  1980.         )
  1981.       ;;>> Set up comment, if any.
  1982.       (if (and (sequencep comment) (not (zerop (length comment))))
  1983.           (let ((before (point))
  1984.             after)
  1985.         (insert comment)
  1986.         (or (eolp) (insert "\n"))
  1987.         (setq after (point))
  1988.         (goto-char before)
  1989.         (while (< (point) after)
  1990.           (insert "Resent-Comment: ")
  1991.           (forward-line 1))))
  1992.       ;; Don't expand aliases in the destination fields
  1993.       ;; of the original message.
  1994.       (let (mail-aliases)
  1995.         (sendmail-send-it)))
  1996.       (kill-buffer tembuf))
  1997.     (rmail-set-attribute "resent" t rmail-current-message)))
  1998.  
  1999. (defvar mail-unsent-separator
  2000.   (concat "^ *---+ +Unsent message follows +---+ *$\\|"
  2001.       "^ *---+ +Returned message +---+ *$\\|"
  2002.       "^ *---+ +Original message +---+ *$\\|"
  2003.       "^ *--+ +begin message +--+ *$\\|"
  2004.       "^ *---+ +Original message follows +---+ *$\\|"
  2005.       "^|? *---+ +Message text follows: +---+ *|?$"))
  2006.  
  2007. (defun rmail-retry-failure ()
  2008.   "Edit a mail message which is based on the contents of the current message.
  2009. For a message rejected by the mail system, extract the interesting headers and
  2010. the body of the original message; otherwise copy the current message."
  2011.   (interactive)
  2012.   (require 'mail-utils)
  2013.   (let (to subj irp2 cc orig-message)
  2014.     (save-excursion
  2015.       ;; Narrow down to just the quoted original message
  2016.       (rmail-beginning-of-message)
  2017.       (let ((case-fold-search t))
  2018.     (or (re-search-forward mail-unsent-separator nil t)
  2019.         (error "Cannot parse this as a failure message")))
  2020.       (save-restriction
  2021.     (narrow-to-region (point) (point-max))
  2022.     ;; Now mail-fetch-field will get from headers of the original message,
  2023.     ;; not from the headers of the rejection.
  2024.     (setq to   (mail-fetch-field "To")
  2025.           subj (mail-fetch-field "Subject")
  2026.           irp2 (mail-fetch-field "In-reply-to")
  2027.           cc   (mail-fetch-field "Cc"))
  2028.     ;; Get the entire text (not headers) of the original message.
  2029.     (setq orig-message
  2030.           (buffer-substring
  2031.            (progn (search-forward "\n\n") (point))
  2032.            (point-max)))))
  2033.     ;; Start sending a new message; default header fields from the original.
  2034.     ;; Turn off the usual actions for initializing the message body
  2035.     ;; because we want to get only the text from the failure message.
  2036.     (let (mail-signature
  2037.       (mail-setup-hook rmail-retry-setup-hook))
  2038.       (if (rmail-start-mail nil to subj irp2 cc (current-buffer))
  2039.       ;; Insert original text as initial text of new draft message.
  2040.       (progn
  2041.         (goto-char (point-max))
  2042.         (insert orig-message)
  2043.         (goto-char (point-min))
  2044.         (end-of-line))))))
  2045.  
  2046. (defun rmail-bury ()
  2047.   "Bury current Rmail buffer and its summary buffer."
  2048.   (interactive)
  2049.   (let ((rmail-buffer (current-buffer)))
  2050.     (if (rmail-summary-exists)
  2051.     (let (window)
  2052.       (while (setq window (get-buffer-window rmail-summary-buffer))
  2053.         (set-window-buffer window (other-buffer rmail-summary-buffer)))
  2054.       (bury-buffer rmail-summary-buffer)))
  2055.     (switch-to-buffer (other-buffer (current-buffer)))
  2056.     (bury-buffer rmail-buffer)))
  2057.  
  2058. (defun rmail-summary-exists ()
  2059.   "Non-nil iff in an RMAIL buffer and an associated summary buffer exists.
  2060. Non-nil value returned is the summary buffer."
  2061.   (and rmail-summary-buffer (buffer-name rmail-summary-buffer)
  2062.        rmail-summary-buffer))
  2063.  
  2064. (defun rmail-summary-displayed ()
  2065.   "t iff in RMAIL buffer and an associated summary buffer is displayed."
  2066.   (and (rmail-summary-exists) (get-buffer-window rmail-summary-buffer)))
  2067.  
  2068. (defvar rmail-redisplay-summary nil
  2069.   "*Non-nil means Rmail should show the summary when it changes.
  2070. This has an effect only if a summary buffer exists.")
  2071.  
  2072. ;; Put the summary buffer back on the screen, if user wants that.
  2073. (defun rmail-maybe-display-summary ()
  2074.   (and (rmail-summary-exists)
  2075.        rmail-redisplay-summary
  2076.        (display-buffer rmail-summary-buffer)))
  2077.  
  2078. ;;;; *** Rmail Specify Inbox Files ***
  2079.  
  2080. (autoload 'set-rmail-inbox-list "rmailmsc"
  2081.   "Set the inbox list of the current RMAIL file to FILE-NAME.
  2082. This may be a list of file names separated by commas.
  2083. If FILE-NAME is empty, remove any inbox list."
  2084.   t)
  2085.  
  2086. ;;;; *** Rmail Commands for Labels ***
  2087.  
  2088. (autoload 'rmail-add-label "rmailkwd"
  2089.   "Add LABEL to labels associated with current RMAIL message.
  2090. Completion is performed over known labels when reading."
  2091.   t)
  2092.  
  2093. (autoload 'rmail-kill-label "rmailkwd"
  2094.   "Remove LABEL from labels associated with current RMAIL message.
  2095. Completion is performed over known labels when reading."
  2096.   t)
  2097.  
  2098. (autoload 'rmail-next-labeled-message "rmailkwd"
  2099.   "Show next message with LABEL.  Defaults to last label used.
  2100. With prefix argument N moves forward N messages with this label."
  2101.   t)
  2102.  
  2103. (autoload 'rmail-previous-labeled-message "rmailkwd"
  2104.   "Show previous message with LABEL.  Defaults to last label used.
  2105. With prefix argument N moves backward N messages with this label."
  2106.   t)
  2107.  
  2108. (autoload 'rmail-read-label "rmailkwd"
  2109.   "PROMPT and read with completion an Rmail message label."
  2110.   t)
  2111.  
  2112. ;;;; *** Rmail Edit Mode ***
  2113.  
  2114. (autoload 'rmail-edit-current-message "rmailedit"
  2115.   "Edit the contents of the current message"
  2116.   t)
  2117.  
  2118. ;;;; *** Rmail Sorting ***
  2119.  
  2120. (autoload 'rmail-sort-by-date "rmailsort"
  2121.   "Sort messages of current Rmail file by date.
  2122. If prefix argument REVERSE is non-nil, sort them in reverse order." t)
  2123.  
  2124. (autoload 'rmail-sort-by-subject "rmailsort"
  2125.   "Sort messages of current Rmail file by subject.
  2126. If prefix argument REVERSE is non-nil, sort them in reverse order." t)
  2127.  
  2128. (autoload 'rmail-sort-by-author "rmailsort"
  2129.   "Sort messages of current Rmail file by author.
  2130. If prefix argument REVERSE is non-nil, sort them in reverse order." t)
  2131.  
  2132. (autoload 'rmail-sort-by-recipient "rmailsort"
  2133.   "Sort messages of current Rmail file by recipient.
  2134. If prefix argument REVERSE is non-nil, sort them in reverse order." t)
  2135.  
  2136. (autoload 'rmail-sort-by-correspondent "rmailsort"
  2137.   "Sort messages of current Rmail file by other correspondent.
  2138. If prefix argument REVERSE is non-nil, sort them in reverse order." t)
  2139.  
  2140. (autoload 'rmail-sort-by-lines "rmailsort"
  2141.   "Sort messages of current Rmail file by number of lines.
  2142. If prefix argument REVERSE is non-nil, sort them in reverse order." t)
  2143.  
  2144. ;;;; *** Rmail Summary Mode ***
  2145.  
  2146. (autoload 'rmail-summary "rmailsum"
  2147.   "Display a summary of all messages, one line per message."
  2148.   t)
  2149.  
  2150. (autoload 'rmail-summary-by-labels "rmailsum"
  2151.   "Display a summary of all messages with one or more LABELS.
  2152. LABELS should be a string containing the desired labels, separated by commas."
  2153.   t)
  2154.  
  2155. (autoload 'rmail-summary-by-recipients "rmailsum"
  2156.   "Display a summary of all messages with the given RECIPIENTS.
  2157. Normally checks the To, From and Cc fields of headers; but if PRIMARY-ONLY
  2158. is non-nil (prefix arg given), only look in the To and From fields.
  2159. RECIPIENTS is a string of regexps separated by commas."
  2160.   t)
  2161.  
  2162. (autoload 'rmail-summary-by-regexp "rmailsum"
  2163.   "Display a summary of all messages according to regexp REGEXP.
  2164. If the regular expression is found in the header of the message
  2165. \(including in the date and other lines, as well as the subject line),
  2166. Emacs will list the header line in the RMAIL-summary."
  2167.   t)
  2168.  
  2169. (autoload 'rmail-summary-by-topic "rmailsum"
  2170.   "Display a summary of all messages with the given SUBJECT.
  2171. Normally checks the Subject field of headers;
  2172. but if WHOLE-MESSAGE is non-nil (prefix arg given), 
  2173.  look in the whole message.
  2174. SUBJECT is a string of regexps separated by commas."
  2175.   t)
  2176.  
  2177. ;;;; *** Rmail output messages to files ***
  2178.  
  2179. (autoload 'rmail-output-to-rmail-file "rmailout"
  2180.   "Append the current message to an Rmail file named FILE-NAME.
  2181. If the file does not exist, ask if it should be created.
  2182. If file is being visited, the message is appended to the Emacs
  2183. buffer visiting that file."
  2184.   t)
  2185.  
  2186. (autoload 'rmail-output "rmailout"
  2187.   "Append this message to Unix mail file named FILE-NAME."
  2188.   t)
  2189.  
  2190. ;;;; *** Rmail undigestification ***
  2191.  
  2192. (autoload 'undigestify-rmail-message "undigest"
  2193.   "Break up a digest message into its constituent messages.
  2194. Leaves original message, deleted, before the undigestified messages."
  2195.   t)
  2196.  
  2197. (provide 'rmail)
  2198.  
  2199. ;;; rmail.el ends here
  2200.